summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinux Build Service Account <lnxbuild@localhost>2016-12-06 01:06:02 -0700
committerLinux Build Service Account <lnxbuild@localhost>2016-12-06 01:06:02 -0700
commitbfba368b8769fa953854f03048e2c57a168463c6 (patch)
tree15cb3c1823e1d92f78591a06f1d96e2b1a7bba91
parent0c442de94db9105f05c84a08647e009174824410 (diff)
parent59f5e90123b8c961c835465fb22cb651e5438b3d (diff)
downloadandroid_packages_apps_Gallery2-bfba368b8769fa953854f03048e2c57a168463c6.tar.gz
android_packages_apps_Gallery2-bfba368b8769fa953854f03048e2c57a168463c6.tar.bz2
android_packages_apps_Gallery2-bfba368b8769fa953854f03048e2c57a168463c6.zip
Merge 59f5e90123b8c961c835465fb22cb651e5438b3d on remote branch
Change-Id: Ife9e0e38b6c55d093a0ac16c94e71328d9d27390
-rwxr-xr-xAndroidManifest.xml19
-rwxr-xr-x[-rw-r--r--]res/values/colors.xml2
-rwxr-xr-x[-rw-r--r--]res/xml/rtsp_settings_preferences.xml3
-rwxr-xr-xsrc/com/android/gallery3d/app/GalleryActivity.java4
-rwxr-xr-xsrc/com/android/gallery3d/app/PhotoPage.java9
-rwxr-xr-xsrc/com/android/gallery3d/app/TimeLinePage.java6
-rwxr-xr-x[-rw-r--r--]src/com/android/gallery3d/data/ClusterAlbum.java31
-rwxr-xr-x[-rw-r--r--]src/com/android/gallery3d/data/FilterDeleteSet.java3
-rwxr-xr-x[-rw-r--r--]src/com/android/gallery3d/data/MediaSet.java20
-rwxr-xr-xsrc/com/android/gallery3d/data/TimeLineTitleMediaItem.java4
-rw-r--r--src/com/android/gallery3d/filtershow/category/TrueScannerPanel.java5
-rw-r--r--src/com/android/gallery3d/glrenderer/GLES20Canvas.java7
-rw-r--r--src/com/android/gallery3d/ui/ActionModeHandler.java4
-rwxr-xr-xsrc/com/android/gallery3d/ui/TimeLineSlotView.java4
-rw-r--r--src/org/codeaurora/gallery3d/video/AbstractPermissionPreferenceActivity.java116
-rw-r--r--src/org/codeaurora/gallery3d/video/SettingsActivity.java93
16 files changed, 273 insertions, 57 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 429488fe4..bfdd8f77a 100755
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -49,6 +49,7 @@
<uses-permission android:name="android.permission.BLUETOOTH" />
<!-- add for guest to set system property -->
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
+ <uses-permission android:name="android.permission.READ_PHONE_STATE" />
<supports-screens android:smallScreens="false"
android:normalScreens="true" android:largeScreens="true"
@@ -83,23 +84,7 @@
<data android:scheme="content" />
<data android:scheme="file" />
<data android:scheme="rtsp" />
- <data android:mimeType="video/mpeg4" />
- <data android:mimeType="video/mp4" />
- <data android:mimeType="video/3gp" />
- <data android:mimeType="video/3gpp" />
- <data android:mimeType="video/3gpp2" />
- <data android:mimeType="video/webm" />
- <data android:mimeType="video/avi" />
- <data android:mimeType="application/sdp" />
- <data android:mimeType="video/mp2t" />
- <data android:mimeType="video/mp2ts" />
- <data android:mimeType="video/x-ms-asf" />
- <data android:mimeType="video/x-ms-wmv" />
- <data android:mimeType="video/x-matroska" />
- <data android:mimeType="video/x-msvideo"/>
- <data android:mimeType="video/divx" />
- <data android:mimeType="video/mkv" />
- <data android:mimeType="video/mpeg" />
+ <data android:mimeType="video/*" />
</intent-filter>
<intent-filter>
<!-- HTTP live support -->
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 7c2ffccd4..6c4a79178 100644..100755
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -27,7 +27,7 @@
<!-- configuration for album page -->
<color name="album_background">#fafafa</color>
- <color name="album_placeholder">#fafafa</color>
+ <color name="album_placeholder">#75000000</color>
<!-- configuration for photo page -->
<color name="photo_background">#1A1A1A</color>
diff --git a/res/xml/rtsp_settings_preferences.xml b/res/xml/rtsp_settings_preferences.xml
index 8e26c4d8c..13842d34e 100644..100755
--- a/res/xml/rtsp_settings_preferences.xml
+++ b/res/xml/rtsp_settings_preferences.xml
@@ -29,7 +29,8 @@
android:summary=""
android:title="@string/buffer_size" />
</PreferenceCategory>
- <PreferenceCategory android:title="@string/apn" >
+ <PreferenceCategory android:title="@string/apn"
+ android:key="apn_category">
<PreferenceScreen
android:key="apn"
android:title="@string/apn" >
diff --git a/src/com/android/gallery3d/app/GalleryActivity.java b/src/com/android/gallery3d/app/GalleryActivity.java
index 93ac5a4bc..e18f1c2c6 100755
--- a/src/com/android/gallery3d/app/GalleryActivity.java
+++ b/src/com/android/gallery3d/app/GalleryActivity.java
@@ -91,10 +91,6 @@ public final class GalleryActivity extends AbstractGalleryActivity implements On
public static final String KEY_FROM_SNAPCAM = "from-snapcam";
public static final String KEY_TOTAL_NUMBER = "total-number";
- //add for TimelinePage and PhotoPage: -1 don't show timeline title, 0 show timeline title
- public static final int CLUSTER_ALBUMSET_NO_TITLE = -1;
- public static final int CLUSTER_ALBUMSET_TIME_TITLE = 0;
-
private static final String TAG = "GalleryActivity";
private Dialog mVersionCheckDialog;
private ListView mDrawerListView;
diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java
index cdd5742fd..161d729da 100755
--- a/src/com/android/gallery3d/app/PhotoPage.java
+++ b/src/com/android/gallery3d/app/PhotoPage.java
@@ -481,7 +481,7 @@ public abstract class PhotoPage extends ActivityState implements
mMediaSet = (FilterDeleteSet) mActivity.getDataManager()
.getMediaSet(mSetPathString);
if (mMediaSet != null && mIsFromTimelineScreen) {
- mMediaSet.setClusterKind(GalleryActivity.CLUSTER_ALBUMSET_NO_TITLE);
+ mMediaSet.setShowAlbumsetTimeTitle(false);
}
if (mMediaSet == null) {
Log.w(TAG, "failed to restore " + mSetPathString);
@@ -933,6 +933,9 @@ public abstract class PhotoPage extends ActivityState implements
private void refreshHidingMessage() {
mHandler.removeMessages(MSG_HIDE_BARS);
+ if (mPhotoView == null) {
+ mPhotoView = (PhotoView) mRootPane.getComponent(0);
+ }
if (!mIsMenuVisible && !mPhotoView.getFilmMode()) {
mHandler.sendEmptyMessageDelayed(MSG_HIDE_BARS, HIDE_BARS_TIMEOUT);
}
@@ -987,7 +990,7 @@ public abstract class PhotoPage extends ActivityState implements
} else {
if (mMediaSet != null && mIsFromTimelineScreen) {
//if back to TimeLinePage, need show timeline title
- mMediaSet.setClusterKind(GalleryActivity.CLUSTER_ALBUMSET_TIME_TITLE);
+ mMediaSet.setShowAlbumsetTimeTitle(true);
}
super.onBackPressed();
mActionBar.setBackGroundDefault();
@@ -1613,7 +1616,7 @@ public abstract class PhotoPage extends ActivityState implements
//if from TimeLinePage, don't show the timeline title
if (mMediaSet != null && mIsFromTimelineScreen) {
- mMediaSet.setClusterKind(GalleryActivity.CLUSTER_ALBUMSET_NO_TITLE);
+ mMediaSet.setShowAlbumsetTimeTitle(false);
}
mActionBar.setDisplayOptions(
diff --git a/src/com/android/gallery3d/app/TimeLinePage.java b/src/com/android/gallery3d/app/TimeLinePage.java
index 978909849..c3c08650b 100755
--- a/src/com/android/gallery3d/app/TimeLinePage.java
+++ b/src/com/android/gallery3d/app/TimeLinePage.java
@@ -281,6 +281,10 @@ public class TimeLinePage extends ActivityState implements
} else {
MediaItem item = mAlbumDataAdapter.get(slotIndex);
if (item == null) return; // Item not ready yet, ignore the click
+ if (mSelectionManager.getSelectedCount() > 0) {
+ if (!ActionModeHandler.isThreadComplete)
+ return;
+ }
mSelectionManager.toggle(item.getPath());
mSlotView.invalidate();
}
@@ -450,7 +454,7 @@ public class TimeLinePage extends ActivityState implements
setLoadingBit(BIT_LOADING_RELOAD);
if (null != mMediaSet) {
//set to show timeline title
- mMediaSet.setClusterKind(GalleryActivity.CLUSTER_ALBUMSET_TIME_TITLE);
+ mMediaSet.setShowAlbumsetTimeTitle(true);
}
mLoadingFailed = false;
mAlbumDataAdapter.resume();
diff --git a/src/com/android/gallery3d/data/ClusterAlbum.java b/src/com/android/gallery3d/data/ClusterAlbum.java
index 4e2cc18ea..df88c48d9 100644..100755
--- a/src/com/android/gallery3d/data/ClusterAlbum.java
+++ b/src/com/android/gallery3d/data/ClusterAlbum.java
@@ -77,7 +77,7 @@ public class ClusterAlbum extends MediaSet implements ContentListener {
@Override
public int getMediaItemCount() {
- if (mKind == ClusterSource.CLUSTER_ALBUMSET_TIME) {
+ if (MediaSet.isShowAlbumsetTimeTitle()) {
return mPaths.size()+1;
}
return mPaths.size();
@@ -90,22 +90,28 @@ public class ClusterAlbum extends MediaSet implements ContentListener {
public void setImageItemCount(int count) {
mImageCount = count;
- if (mTimelineTitleMediaItem != null && mKind == ClusterSource.CLUSTER_ALBUMSET_TIME) {
+ if (mTimelineTitleMediaItem != null && MediaSet.isShowAlbumsetTimeTitle()) {
mTimelineTitleMediaItem.setImageCount(count);
}
}
public void setVideoItemCount(int count) {
mVideoCount = count;
- if (mTimelineTitleMediaItem != null && mKind == ClusterSource.CLUSTER_ALBUMSET_TIME) {
+ if (mTimelineTitleMediaItem != null && MediaSet.isShowAlbumsetTimeTitle()) {
mTimelineTitleMediaItem.setVideoCount(count);
}
}
+ private void updateItemCounts() {
+ setImageItemCount(mImageCount);
+ setVideoItemCount(mVideoCount);
+ }
+
@Override
public ArrayList<MediaItem> getMediaItem(int start, int count) {
//return getMediaItemFromPath(mPaths, start, count, mDataManager);
- if (mKind == ClusterSource.CLUSTER_ALBUMSET_TIME) {
+ updateItemCounts();
+ if (MediaSet.isShowAlbumsetTimeTitle()) {
if (mPaths.size() <= 0) return null;
if (start == 0) {
ArrayList<MediaItem> mediaItemList = new ArrayList<MediaItem>();
@@ -163,7 +169,7 @@ public class ClusterAlbum extends MediaSet implements ContentListener {
@Override
public int getTotalMediaItemCount() {
- if (mKind == ClusterSource.CLUSTER_ALBUMSET_TIME) {
+ if (MediaSet.isShowAlbumsetTimeTitle()) {
return mPaths.size()+1;
}
return mPaths.size();
@@ -172,7 +178,7 @@ public class ClusterAlbum extends MediaSet implements ContentListener {
@Override
public int getMediaType() {
// return correct type of Timeline Title.
- if (mKind == ClusterSource.CLUSTER_ALBUMSET_TIME) {
+ if (MediaSet.isShowAlbumsetTimeTitle()) {
return MEDIA_TYPE_TIMELINE_TITLE;
}
return super.getMediaType();
@@ -203,7 +209,7 @@ public class ClusterAlbum extends MediaSet implements ContentListener {
@Override
public int getSupportedOperations() {
// Timeline title item doesn't support anything, just its sub objects supported.
- if (mKind == ClusterSource.CLUSTER_ALBUMSET_TIME) {
+ if (MediaSet.isShowAlbumsetTimeTitle()) {
return 0;
}
return SUPPORT_SHARE | SUPPORT_DELETE | SUPPORT_INFO;
@@ -232,15 +238,4 @@ public class ClusterAlbum extends MediaSet implements ContentListener {
return mTimelineTitleMediaItem;
}
- public void setClusterKind(int kind) {
- if (mKind == kind) {
- return;
- }
- mKind = kind;
- refreshImageItemCount();
- }
-
- private void refreshImageItemCount() {
- setImageItemCount(mImageCount);
- }
}
diff --git a/src/com/android/gallery3d/data/FilterDeleteSet.java b/src/com/android/gallery3d/data/FilterDeleteSet.java
index 799ea0e16..d0b5b0a90 100644..100755
--- a/src/com/android/gallery3d/data/FilterDeleteSet.java
+++ b/src/com/android/gallery3d/data/FilterDeleteSet.java
@@ -275,7 +275,4 @@ public class FilterDeleteSet extends MediaSet implements ContentListener {
return mCurrent.size();
}
- public void setClusterKind(int kind) {
- mBaseSet.setClusterKind(kind);
- }
}
diff --git a/src/com/android/gallery3d/data/MediaSet.java b/src/com/android/gallery3d/data/MediaSet.java
index d0f0ec3c4..9d0233ef0 100644..100755
--- a/src/com/android/gallery3d/data/MediaSet.java
+++ b/src/com/android/gallery3d/data/MediaSet.java
@@ -385,5 +385,23 @@ public abstract class MediaSet extends MediaObject {
}
}
- public void setClusterKind(int kind){};
+ private static boolean sShowTitle = true;
+
+ /**
+ * add for TimelinePage
+ * @param showTitle
+ * true: in TimelinePage we need show TimeTitle
+ * false: we don't need TimeTitle
+ */
+ public static void setShowAlbumsetTimeTitle(boolean showTitle) {
+ sShowTitle = showTitle;
+ }
+
+ /**
+ * @return true: in TimelinePage we need show TimeTitle
+ * false: we don't need TimeTitle
+ */
+ public static boolean isShowAlbumsetTimeTitle() {
+ return sShowTitle;
+ }
}
diff --git a/src/com/android/gallery3d/data/TimeLineTitleMediaItem.java b/src/com/android/gallery3d/data/TimeLineTitleMediaItem.java
index cb24c669b..ee1bbba72 100755
--- a/src/com/android/gallery3d/data/TimeLineTitleMediaItem.java
+++ b/src/com/android/gallery3d/data/TimeLineTitleMediaItem.java
@@ -30,8 +30,8 @@ import com.android.gallery3d.util.ThreadPool.Job;
public class TimeLineTitleMediaItem extends MediaItem {
private static final String TAG = "TimeLineTitleMediaItem";
private String mTitle;
- private int mPhotoCount;
- private int mVideoCount;
+ private static int mPhotoCount;
+ private static int mVideoCount;
public TimeLineTitleMediaItem(Path path) {
super(path);
diff --git a/src/com/android/gallery3d/filtershow/category/TrueScannerPanel.java b/src/com/android/gallery3d/filtershow/category/TrueScannerPanel.java
index 535273da9..f5f57645c 100644
--- a/src/com/android/gallery3d/filtershow/category/TrueScannerPanel.java
+++ b/src/com/android/gallery3d/filtershow/category/TrueScannerPanel.java
@@ -56,8 +56,11 @@ public class TrueScannerPanel extends BasicGeometryPanel {
mEditorName.setText(R.string.truescanner);
mBottomPanel.setVisibility(View.VISIBLE);
- mTrueScannerEditor.initCords();
final FilterShowActivity activity = (FilterShowActivity) getActivity();
+ if (mTrueScannerEditor == null) {
+ mTrueScannerEditor = (TrueScannerEditor) activity.getEditor(TrueScannerEditor.ID);
+ }
+ mTrueScannerEditor.initCords();
mExitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
diff --git a/src/com/android/gallery3d/glrenderer/GLES20Canvas.java b/src/com/android/gallery3d/glrenderer/GLES20Canvas.java
index 4ead1315e..4c7ae942e 100644
--- a/src/com/android/gallery3d/glrenderer/GLES20Canvas.java
+++ b/src/com/android/gallery3d/glrenderer/GLES20Canvas.java
@@ -23,6 +23,7 @@ import android.opengl.GLUtils;
import android.opengl.Matrix;
import android.util.Log;
+import com.android.gallery3d.common.ApiHelper;
import com.android.gallery3d.util.IntArray;
import java.nio.Buffer;
@@ -291,6 +292,12 @@ public class GLES20Canvas implements GLCanvas {
mMeshProgram = assembleProgram(meshVertexShader, textureFragmentShader, mMeshParameters);
GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);
checkError();
+
+ if (ApiHelper.USE_888_PIXEL_FORMAT) {
+ GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 2);
+ } else {
+ GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
+ }
}
private static FloatBuffer createBuffer(float[] values) {
diff --git a/src/com/android/gallery3d/ui/ActionModeHandler.java b/src/com/android/gallery3d/ui/ActionModeHandler.java
index 04d361a19..0b367d7dc 100644
--- a/src/com/android/gallery3d/ui/ActionModeHandler.java
+++ b/src/com/android/gallery3d/ui/ActionModeHandler.java
@@ -67,6 +67,8 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi
public boolean onActionItemClicked(MenuItem item);
}
+ public static boolean isThreadComplete = false;
+
private final AbstractGalleryActivity mActivity;
private final MenuExecutor mMenuExecutor;
private final SelectionManager mSelectionManager;
@@ -452,6 +454,7 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi
// Disable share actions until share intent is in good shape
if (mSharePanoramaMenuItem != null) mSharePanoramaMenuItem.setEnabled(false);
if (mShareMenuItem != null) mShareMenuItem.setEnabled(false);
+ isThreadComplete = false;
// Generate sharing intent and update supported operations in the background
// The task can take a long time and be canceled in the mean time.
@@ -550,6 +553,7 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi
showShareMaxDialogIfNeed(canShare);
mShareMenuItem.setEnabled(canShare);
+ isThreadComplete = true;
shareIntent = share_intent;
}
}
diff --git a/src/com/android/gallery3d/ui/TimeLineSlotView.java b/src/com/android/gallery3d/ui/TimeLineSlotView.java
index 7dcf4ef5f..2a088c208 100755
--- a/src/com/android/gallery3d/ui/TimeLineSlotView.java
+++ b/src/com/android/gallery3d/ui/TimeLineSlotView.java
@@ -658,10 +658,6 @@ public class TimeLineSlotView extends GLView {
}
if (!rowStart) {
col = ((int) x) / (mSlotWidth + mSlotGap);
- if (TextUtils.getLayoutDirectionFromLocale(Locale.getDefault())
- == View.LAYOUT_DIRECTION_RTL) {
- col = mUnitCount - col;
- }
if (row * mUnitCount + col >= count) {
break;
}
diff --git a/src/org/codeaurora/gallery3d/video/AbstractPermissionPreferenceActivity.java b/src/org/codeaurora/gallery3d/video/AbstractPermissionPreferenceActivity.java
new file mode 100644
index 000000000..a6be5afeb
--- /dev/null
+++ b/src/org/codeaurora/gallery3d/video/AbstractPermissionPreferenceActivity.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2016, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.codeaurora.gallery3d.video;
+
+import android.Manifest;
+import android.content.pm.PackageManager;
+import android.os.Build;
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+
+import java.util.ArrayList;
+
+public abstract class AbstractPermissionPreferenceActivity extends PreferenceActivity {
+
+ public static final int PERMISSION_REQUEST_PHONE = 1;
+ private boolean permissionGranted = false;
+
+ protected abstract void onGetPermissionsSuccess();
+ protected abstract void onGetPermissionsFailure();
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ requestPhonePermission();
+ }
+
+ private void requestPhonePermission() {
+ String[] permissions = {
+ Manifest.permission.READ_PHONE_STATE
+ };
+ requestPermission(permissions, PERMISSION_REQUEST_PHONE);
+ }
+
+ protected void requestPermission(String[] permissions, int requestCode) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
+ permissionGranted = true;
+ return;
+ }
+
+ boolean needRequest = false;
+ ArrayList<String> permissionList = new ArrayList<String>();
+ for (String permission : permissions) {
+ if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
+ permissionList.add(permission);
+ needRequest = true;
+ }
+ }
+
+ if (needRequest) {
+ int count = permissionList.size();
+ if (count > 0) {
+ String[] permissionArray = new String[count];
+ for (int i = 0; i < count; i++) {
+ permissionArray[i] = permissionList.get(i);
+ }
+
+ requestPermissions(permissionArray, requestCode);
+ }
+ }
+ permissionGranted = !needRequest;
+ }
+
+ private boolean checkPermissionGrantResults(int[] grantResults) {
+ for (int result : grantResults) {
+ if (result != PackageManager.PERMISSION_GRANTED) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String[] permissions,
+ int[] grantResults) {
+ permissionGranted = checkPermissionGrantResults(grantResults);
+ switch (requestCode) {
+ case PERMISSION_REQUEST_PHONE: {
+ if (permissionGranted) {
+ onGetPermissionsSuccess();
+ } else {
+ onGetPermissionsFailure();
+ }
+ }
+ }
+ }
+
+ protected boolean isPermissionGranted() {
+ return permissionGranted;
+ }
+}
diff --git a/src/org/codeaurora/gallery3d/video/SettingsActivity.java b/src/org/codeaurora/gallery3d/video/SettingsActivity.java
index b0bd65c32..f2b1bebac 100644
--- a/src/org/codeaurora/gallery3d/video/SettingsActivity.java
+++ b/src/org/codeaurora/gallery3d/video/SettingsActivity.java
@@ -9,9 +9,13 @@ import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
+import android.preference.PreferenceCategory;
+import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.provider.Settings.System;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.method.DigitsKeyListener;
import android.util.Log;
@@ -22,8 +26,9 @@ import com.android.gallery3d.common.ApiHelper;
import com.android.gallery3d.common.ApiHelper.SystemProperties;
import java.util.ArrayList;
+import java.util.List;
-public class SettingsActivity extends PreferenceActivity {
+public class SettingsActivity extends AbstractPermissionPreferenceActivity {
private static final String LOG_TAG = "SettingsActivity";
@@ -33,6 +38,7 @@ public class SettingsActivity extends PreferenceActivity {
private static final String PREFERENCE_CACHE_MIN_SIZE = "cache_min_size";
private static final String PREFERENCE_CACHE_MAX_SIZE = "cache_max_size";
public static final String PREFERENCE_BUFFER_SIZE = "buffer_size";
+ public static final String PREFERENCE_APN_CATEGORY = "apn_category";
public static final String PREFERENCE_APN = "apn";
private static final String PACKAGE_NAME = "com.android.settings";
@@ -45,11 +51,14 @@ public class SettingsActivity extends PreferenceActivity {
private static final int RTP_MIN_PORT = 1;
private static final int RTP_MAX_PORT = 2;
private static final int BUFFER_SIZE = 3;
+ private static final boolean DBG = true;
+ private static final String TAG = SettingsActivity.class.getSimpleName();
private SharedPreferences mPref;
private EditTextPreference mRtpMinPort;
private EditTextPreference mRtpMaxPort;
private EditTextPreference mBufferSize;
+ private PreferenceCategory mApnCategory;
private PreferenceScreen mApn;
private static final int SELECT_APN = 1;
@@ -61,6 +70,19 @@ public class SettingsActivity extends PreferenceActivity {
private boolean mUseNvOperatorForEhrpd = SystemProperties.getBoolean(
"persist.radio.use_nv_for_ehrpd", false);
+ private SubscriptionManager mSubscriptionManager;
+ private List<SubscriptionInfo> mActiveSubInfos;
+
+ @Override
+ protected void onGetPermissionsSuccess() {
+ init();
+ }
+
+ @Override
+ protected void onGetPermissionsFailure() {
+ finish();
+ }
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -70,6 +92,7 @@ public class SettingsActivity extends PreferenceActivity {
mRtpMinPort = (EditTextPreference) findPreference(PREFERENCE_RTP_MINPORT);
mRtpMaxPort = (EditTextPreference) findPreference(PREFERENCE_RTP_MAXPORT);
mBufferSize = (EditTextPreference) findPreference(PREFERENCE_BUFFER_SIZE);
+ mApnCategory = (PreferenceCategory) findPreference(PREFERENCE_APN_CATEGORY);
mApn = (PreferenceScreen) findPreference(PREFERENCE_APN);
setPreferenceListener(RTP_MIN_PORT, mRtpMinPort);
@@ -81,6 +104,74 @@ public class SettingsActivity extends PreferenceActivity {
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
ab.setDisplayHomeAsUpEnabled(true);
ab.setTitle(R.string.setting);
+
+ if (isPermissionGranted()) {
+ init();
+ }
+ }
+
+ private void init() {
+ mSubscriptionManager = SubscriptionManager.from(this);
+ mSubscriptionManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangeListener);
+ // Initialize mActiveSubInfo
+ int max = mSubscriptionManager.getActiveSubscriptionInfoCountMax();
+ mActiveSubInfos = new ArrayList<SubscriptionInfo>(max);
+
+ initializeSubscriptions();
+
+ if (!hasActiveSubscriptions()) {
+ ((PreferenceGroup)mApnCategory).removePreference(mApn);
+ getPreferenceScreen().removePreference(mApnCategory);
+
+ }
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ if (null != mSubscriptionManager) {
+ mSubscriptionManager
+ .removeOnSubscriptionsChangedListener(mOnSubscriptionsChangeListener);
+ }
+ }
+
+ private final SubscriptionManager.OnSubscriptionsChangedListener mOnSubscriptionsChangeListener
+ = new SubscriptionManager.OnSubscriptionsChangedListener() {
+ @Override
+ public void onSubscriptionsChanged() {
+ if (DBG) Log.i(TAG, "onSubscriptionsChanged:");
+ initializeSubscriptions();
+ if (hasActiveSubscriptions()) {
+ getPreferenceScreen().addPreference(mApnCategory);
+ mApnCategory.addPreference(mApn);
+ } else{
+ ((PreferenceGroup)mApnCategory).removePreference(mApn);
+ getPreferenceScreen().removePreference(mApnCategory);
+ }
+ }
+ };
+
+ private void initializeSubscriptions() {
+ if (isDestroyed()) { // Process preferences in activity only if its not destroyed
+ return;
+ }
+ if (DBG) Log.i(TAG, "initializeSubscriptions:+");
+
+ // Before updating the the active subscription list check
+ // if tab updating is needed as the list is changing.
+ List<SubscriptionInfo> sil = mSubscriptionManager.getActiveSubscriptionInfoList();
+
+ // Update to the active subscription list
+ mActiveSubInfos.clear();
+ if (sil != null) {
+ mActiveSubInfos.addAll(sil);
+ }
+
+ if (DBG) Log.i(TAG, "initializeSubscriptions:-");
+ }
+
+ private boolean hasActiveSubscriptions() {
+ return mActiveSubInfos.size() > 0;
}
@Override