Browse Source

ROMControl : Auto Immersive Mode (2/2)

Automatically enables the immersive mode when someone opens the selected app.

PS2: Fixed up the code/logic.
PS4: Removed whitespaces
PS5: add new drawable

Change-Id: Ic4d6f3188c31b6a8f6878f7485b96d8b53be5f1e
Signed-off-by: Umair Khan <omerjerk@gmail.com>
Umair Khan 8 years ago
parent
commit
c5d39a177c

+ 2
- 2
build.gradle View File

@@ -3,7 +3,7 @@ buildscript {
3 3
         mavenCentral()
4 4
     }
5 5
     dependencies {
6
-        classpath 'com.android.tools.build:gradle:0.7.+'
6
+        classpath 'com.android.tools.build:gradle:0.11.+'
7 7
     }
8 8
 }
9 9
 apply plugin: 'android'
@@ -16,7 +16,7 @@ dependencies {
16 16
 
17 17
 android {
18 18
     compileSdkVersion 119
19
-    buildToolsVersion "19"
19
+    buildToolsVersion "19.1.0"
20 20
 
21 21
     sourceSets {
22 22
         main {

+ 2
- 2
gradle/wrapper/gradle-wrapper.properties View File

@@ -1,6 +1,6 @@
1
-#Sun Dec 15 17:49:10 EST 2013
1
+#Fri Jun 13 21:00:34 IST 2014
2 2
 distributionBase=GRADLE_USER_HOME
3 3
 distributionPath=wrapper/dists
4 4
 zipStoreBase=GRADLE_USER_HOME
5 5
 zipStorePath=wrapper/dists
6
-distributionUrl=http\://services.gradle.org/distributions/gradle-1.9-all.zip
6
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip

BIN
res/drawable-hdpi/ic_rom_control_auto_immersive.png View File


BIN
res/drawable-mdpi/ic_rom_control_auto_immersive.png View File


BIN
res/drawable-xhdpi/ic_rom_control_auto_immersive.png View File


+ 12
- 0
res/layout/fragment_auto_immersive_settings.xml View File

@@ -0,0 +1,12 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+
3
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
4
+    android:orientation="vertical" android:layout_width="match_parent"
5
+    android:layout_height="match_parent">
6
+
7
+    <ListView
8
+        android:id="@+id/listview_auto_immersive"
9
+        android:layout_width="match_parent"
10
+        android:layout_height="match_parent" />
11
+
12
+</LinearLayout>

+ 5
- 0
res/menu/auto_immersive.xml View File

@@ -0,0 +1,5 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+
3
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
4
+    <item android:title="@string/add_immersive_item" android:id="@+id/menu_add_app" android:showAsAction="always|withText"/>
5
+</menu>

+ 3
- 0
res/values/arrays.xml View File

@@ -33,6 +33,7 @@
33 33
         <item>@string/category_ribbons</item>
34 34
         <item>@string/category_animations</item>
35 35
         <item>@string/category_led</item>
36
+        <item>@string/category_auto_immersive</item>
36 37
     </string-array>
37 38
     <string-array name="navigation_drawer_values" translatable="false">
38 39
         <item>about_aokp</item>
@@ -49,6 +50,7 @@
49 50
         <item>ribbons</item>
50 51
         <item>animations</item>
51 52
         <item>led</item>
53
+        <item>auto_immersive</item>
52 54
     </string-array>
53 55
     <string-array name="navigation_drawer_icons" translatable="false">
54 56
         <item>@drawable/ic_rom_control_about</item>
@@ -65,5 +67,6 @@
65 67
         <item>@drawable/ic_rom_control_ribbon</item>
66 68
         <item>@drawable/ic_rom_control_animations</item>
67 69
         <item>@drawable/ic_rom_control_led</item>
70
+        <item>@drawable/ic_rom_control_auto_immersive</item>
68 71
     </string-array>
69 72
 </resources>

+ 4
- 0
res/values/strings.xml View File

@@ -39,6 +39,7 @@
39 39
     <string name="category_ribbons">Ribbons</string>
40 40
     <string name="category_animations">Animations</string>
41 41
     <string name="category_led">LED</string>
42
+    <string name="category_auto_immersive">Auto Immersive</string>
42 43
 
43 44
     <!-- Menu Items -->
44 45
     <string name="menu_show_drawer_icon">Show in app drawer</string>
@@ -575,4 +576,7 @@
575 576
     <string name="excluded_apps_title">Excluded applications</string>
576 577
     <string name="excluded_apps_summary">Excluded applications will not show up as lockscreen notifications</string>
577 578
     <string name="notification_color">Notification background color</string>
579
+
580
+    <!-- Auto Immersive Settings -->
581
+    <string name="add_immersive_item">Add</string>
578 582
 </resources>

+ 4
- 0
src/com/aokp/romcontrol/MainActivity.java View File

@@ -45,6 +45,7 @@ import com.aokp.romcontrol.fragments.SoundSettingsFragment;
45 45
 import com.aokp.romcontrol.fragments.about.AboutTabHostFragment;
46 46
 import com.aokp.romcontrol.fragments.navbar.NavbarTabHostFragment;
47 47
 import com.aokp.romcontrol.fragments.toggles.TogglesTabHostFragment;
48
+import com.aokp.romcontrol.fragments.AutoImmersiveSettingsFragment;
48 49
 
49 50
 
50 51
 public class MainActivity extends Activity
@@ -144,6 +145,9 @@ public class MainActivity extends Activity
144 145
         else if ("led".equals(item)) {
145 146
             fragment = new LedSettingsFragment();
146 147
         }
148
+        else if ("auto_immersive".equals(item)) {
149
+            fragment = new AutoImmersiveSettingsFragment();
150
+        }
147 151
         else {
148 152
             // who knows
149 153
             fragment = new AboutTabHostFragment();

+ 159
- 0
src/com/aokp/romcontrol/fragments/AutoImmersiveSettingsFragment.java View File

@@ -0,0 +1,159 @@
1
+/*
2
+ * Copyright (C) 2013 The Android Open Kang Project
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *      http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+package com.aokp.romcontrol.fragments;
18
+
19
+import android.app.Activity;
20
+import android.app.Fragment;
21
+import android.content.ComponentName;
22
+import android.content.Context;
23
+import android.content.Intent;
24
+import android.content.pm.ApplicationInfo;
25
+import android.content.pm.PackageManager;
26
+import android.os.Bundle;
27
+import android.provider.Settings;
28
+import android.view.LayoutInflater;
29
+import android.view.Menu;
30
+import android.view.MenuInflater;
31
+import android.view.MenuItem;
32
+import android.view.View;
33
+import android.view.ViewGroup;
34
+import android.widget.ArrayAdapter;
35
+import android.widget.ListView;
36
+
37
+import com.aokp.romcontrol.R;
38
+import com.aokp.romcontrol.util.ShortcutPickerHelper;
39
+import com.google.android.apps.dashclock.ui.SwipeDismissListViewTouchListener;
40
+
41
+import java.util.ArrayList;
42
+
43
+public class AutoImmersiveSettingsFragment extends Fragment {
44
+
45
+    private Context mContext;
46
+
47
+    private ArrayList<String> appsPackageList = new ArrayList<String>();
48
+    private ArrayList<String> appsNameList = new ArrayList<String>();
49
+    private ArrayAdapter<String> mArrayAdapter;
50
+
51
+    public AutoImmersiveSettingsFragment() {
52
+
53
+    }
54
+
55
+    @Override
56
+    public void onCreate(Bundle savedInstanceState) {
57
+        super.onCreate(savedInstanceState);
58
+        setHasOptionsMenu(true);
59
+    }
60
+
61
+    @Override
62
+    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
63
+        View v = inflater.inflate(R.layout.fragment_auto_immersive_settings, container, false);
64
+        mContext = getActivity();
65
+        appsPackageList = Settings.AOKP.getArrayList(mContext.getContentResolver(),
66
+                Settings.AOKP.KEY_AUTO_IMMERSIVE_ARRAY);
67
+        appsNameList = generateApplicationsNameList(appsPackageList);
68
+        ListView mAppsListView = (ListView) v.findViewById(R.id.listview_auto_immersive);
69
+        SwipeDismissListViewTouchListener touchListener =
70
+                new SwipeDismissListViewTouchListener(
71
+                        mAppsListView,
72
+                        new SwipeDismissListViewTouchListener.DismissCallbacks() {
73
+                            @Override
74
+                            public boolean canDismiss(int position) {
75
+                                return true;
76
+                            }
77
+
78
+                            @Override
79
+                            public void onDismiss(ListView listView, int[] reverseSortedPositions) {
80
+                                for (int position : reverseSortedPositions) {
81
+                                    mArrayAdapter.remove(mArrayAdapter.getItem(position));
82
+                                    appsPackageList.remove(position);
83
+                                }
84
+                                mArrayAdapter.notifyDataSetChanged();
85
+                                Settings.AOKP.putArrayList(mContext.getContentResolver(),
86
+                                        Settings.AOKP.KEY_AUTO_IMMERSIVE_ARRAY, appsPackageList);
87
+                            }
88
+                        });
89
+        mAppsListView.setOnTouchListener(touchListener);
90
+        mAppsListView.setOnScrollListener(touchListener.makeScrollListener());
91
+        mArrayAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1, appsNameList);
92
+        mAppsListView.setAdapter(mArrayAdapter);
93
+        return v;
94
+    }
95
+
96
+    @Override
97
+    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
98
+        super.onCreateOptionsMenu(menu, inflater);
99
+        inflater.inflate(R.menu.auto_immersive, menu);
100
+    }
101
+
102
+    @Override
103
+    public boolean onOptionsItemSelected(MenuItem item) {
104
+        switch (item.getItemId()) {
105
+            case R.id.menu_add_app:
106
+                showAppChooserDialog();
107
+                return true;
108
+            default:
109
+                return false;
110
+        }
111
+    }
112
+
113
+    private void showAppChooserDialog() {
114
+        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
115
+        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
116
+
117
+        Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
118
+        pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
119
+        this.startActivityForResult(pickIntent, ShortcutPickerHelper.REQUEST_PICK_APPLICATION);
120
+    }
121
+
122
+    public void onActivityResult(int requestCode, int resultCode, Intent data) {
123
+
124
+        if (resultCode == Activity.RESULT_OK) {
125
+            switch (requestCode) {
126
+                case ShortcutPickerHelper.REQUEST_PICK_APPLICATION:
127
+                    ComponentName componentName = data.getComponent();
128
+                    final String packageName = componentName.getPackageName();
129
+                    if (!appsPackageList.contains(packageName)) {
130
+                        appsPackageList.add(packageName);
131
+                        appsNameList.add(getApplicationName(mContext.getPackageManager(), packageName));
132
+                        Settings.AOKP.putArrayList(mContext.getContentResolver(), Settings.AOKP.KEY_AUTO_IMMERSIVE_ARRAY, appsPackageList);
133
+                        mArrayAdapter.notifyDataSetChanged();
134
+                        break;
135
+                    }
136
+            }
137
+        }
138
+    }
139
+
140
+    private ArrayList<String> generateApplicationsNameList (ArrayList<String> appsPackageList) {
141
+
142
+        final PackageManager pm = mContext.getPackageManager();
143
+        ArrayList<String> appsNames = new ArrayList<String>();
144
+        for (String mPackage : appsPackageList) {
145
+            appsNames.add(getApplicationName(pm, mPackage));
146
+        }
147
+        return appsNames;
148
+    }
149
+
150
+    private String getApplicationName(PackageManager pm, String packageName) {
151
+        ApplicationInfo ai;
152
+        try {
153
+            ai = pm.getApplicationInfo( packageName, 0);
154
+        } catch (PackageManager.NameNotFoundException e) {
155
+            ai = null;
156
+        }
157
+        return (String) (ai != null ? pm.getApplicationLabel(ai) : packageName);
158
+    }
159
+}