aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authord34d <clark@cyngn.com>2015-08-11 09:04:15 -0700
committerSteve Kondik <steve@cyngn.com>2016-11-02 21:31:59 -0700
commit2d2e49c3e4a434c115d7cb1dd99d9f522ae2bece (patch)
tree41c1f24b71178a648b971693649d68ee812a5a64
parent8f1a21d4b8111c8f726a8c70ba496441a487507e (diff)
downloadandroid_packages_apps_CMFileManager-2d2e49c3e4a434c115d7cb1dd99d9f522ae2bece.tar.gz
android_packages_apps_CMFileManager-2d2e49c3e4a434c115d7cb1dd99d9f522ae2bece.tar.bz2
android_packages_apps_CMFileManager-2d2e49c3e4a434c115d7cb1dd99d9f522ae2bece.zip
Add support for showing and moving files with CMFM [1/2]
Change-Id: I6851acf05a279a1b83bd041a4d90c8238892765d
-rw-r--r--AndroidManifest.xml8
-rw-r--r--res/values/colors.xml2
-rw-r--r--res/values/strings.xml14
-rw-r--r--res/values/styles.xml18
-rw-r--r--src/com/cyanogenmod/filemanager/activities/MoveDownloadedFileActivity.java71
-rw-r--r--src/com/cyanogenmod/filemanager/activities/PickerActivity.java4
-rw-r--r--src/com/cyanogenmod/filemanager/service/MoveFileService.java192
7 files changed, 305 insertions, 4 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 3135460d..57a81b06 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -142,6 +142,7 @@
android:label="@string/picker"
android:uiOptions="none"
android:configChanges="orientation|keyboardHidden|screenSize"
+ android:theme="@style/FileManager.Theme.PickerActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
@@ -240,6 +241,11 @@
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
+
+ <activity android:name=".activities.MoveDownloadedFileActivity"
+ android:theme="@style/FileManager.Theme.Transparent"
+ android:exported="true"/>
+
<service android:name=".providers.secure.SecureCacheCleanupService">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
@@ -248,6 +254,8 @@
</intent-filter>
</service>
+ <service android:name=".service.MoveFileService" android:exported="false" />
+
</application>
</manifest>
diff --git a/res/values/colors.xml b/res/values/colors.xml
index b2c7f861..592b5007 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -182,4 +182,6 @@
<color name="open_file_progress_dialog_file_color">#de000000</color>
<color name="open_file_progress_dialog_message_color">#8b000000</color>
+
+ <color name="picker_activity_window_bg_color">#99000000</color>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index fd166e67..24d6b2f5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -936,4 +936,18 @@
<string name="docs">Docs</string>
<string name="apps">Apps</string>
<string name="archives">Archives</string>
+
+ <!-- Moving file notifications -->
+ <string name="moving_file_notification_title">Moving file</string>
+ <string name="move_complete_notification_title">Move complete</string>
+ <string name="move_complete_notification_description">Open location</string>
+ <string name="move_complete_notification_share_link">Share link</string>
+ <!-- Moving file error notifications -->
+ <string name="moving_file_failed_notification_title">Unable to move</string>
+ <string name="moving_file_failed_not_enough_space">Not enough space in source. Free more space before retrying.</string>
+ <string name="moving_file_failed_no_provider_connection">Tap to check account connection</string>
+ <string name="moving_file_failed_no_data_connection">Check data connection and tap to retry</string>
+ <string name="moving_file_failed_generic">Tap to retry</string>
+ <string name="moving_file_failed_retry_action">Retry</string>
+ <string name="moving_file_failed_upgrade_action">Upgrade</string>
</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 59827cab..fe9de189 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -114,6 +114,24 @@
<item name="android:homeAsUpIndicator">@drawable/material_ripple_up_arrow</item>
</style>
+ <style name="FileManager.Theme.Transparent" parent="android:Theme">
+ <item name="android:windowIsTranslucent">true</item>
+ <item name="android:windowBackground">@android:color/transparent</item>
+ <item name="android:windowContentOverlay">@null</item>
+ <item name="android:windowNoTitle">true</item>
+ <item name="android:windowIsFloating">true</item>
+ <item name="android:backgroundDimEnabled">false</item>
+ </style>
+
+ <style name="FileManager.Theme.PickerActivity" parent="android:Theme.Material.Light">
+ <item name="android:windowIsTranslucent">true</item>
+ <item name="android:windowBackground">@android:color/transparent</item>
+ <item name="android:windowContentOverlay">@null</item>
+ <item name="android:windowNoTitle">true</item>
+ <item name="android:backgroundDimEnabled">true</item>
+ <item name="android:backgroundDimAmount">0.6</item>
+ </style>
+
<!-- Action bar -->
<style name="FileManager.Widget.ActionBar.White" parent="@android:style/Widget.Material.Light.ActionBar">
<item name="android:textColorPrimary">@android:color/white</item>
diff --git a/src/com/cyanogenmod/filemanager/activities/MoveDownloadedFileActivity.java b/src/com/cyanogenmod/filemanager/activities/MoveDownloadedFileActivity.java
new file mode 100644
index 00000000..e8de1d42
--- /dev/null
+++ b/src/com/cyanogenmod/filemanager/activities/MoveDownloadedFileActivity.java
@@ -0,0 +1,71 @@
+/*
+* Copyright (C) 2015 The CyanogenMod Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package com.cyanogenmod.filemanager.activities;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+import com.cyanogenmod.filemanager.service.MoveFileService;
+
+public class MoveDownloadedFileActivity extends Activity {
+ private static final String TAG = MoveDownloadedFileActivity.class.getSimpleName();
+ private static final boolean DEBUG = false;
+
+ private static final String EXTRA_FILE_PATH = "extra_file_path";
+
+ private static final int REQUEST_MOVE = 1000;
+
+ private String mFilePath;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ if (savedInstanceState == null) {
+ Intent intent = getIntent();
+ if (intent == null || !intent.hasExtra(EXTRA_FILE_PATH)) {
+ Log.w(TAG, "Null intent or no file specified");
+ finish();
+ } else {
+ mFilePath = intent.getStringExtra(EXTRA_FILE_PATH);
+ Intent moveIntent = new Intent(this, PickerActivity.class);
+ moveIntent.setAction(PickerActivity.INTENT_FOLDER_SELECT);
+ moveIntent.putExtra(PickerActivity.EXTRA_ACTION,
+ PickerActivity.ACTION_MODE.MOVE.ordinal());
+ startActivityForResult(moveIntent, REQUEST_MOVE);
+ }
+ }
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == REQUEST_MOVE) {
+ if (resultCode == RESULT_OK && data.hasExtra(PickerActivity.EXTRA_FOLDER_PATH)) {
+ String destinationPath = data.getStringExtra(PickerActivity.EXTRA_FOLDER_PATH);
+ if (DEBUG) Log.d(TAG, String.format("Moving %s to %s", mFilePath, destinationPath));
+ Intent intent = new Intent(this, MoveFileService.class);
+ intent.putExtra(MoveFileService.EXTRA_SOURCE_FILE_PATH, mFilePath);
+ intent.putExtra(MoveFileService.EXTRA_DESTINATION_FILE_PATH, destinationPath);
+ startService(intent);
+ }
+ } else {
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+ finish();
+ }
+} \ No newline at end of file
diff --git a/src/com/cyanogenmod/filemanager/activities/PickerActivity.java b/src/com/cyanogenmod/filemanager/activities/PickerActivity.java
index 9197c12d..5dcdfae1 100644
--- a/src/com/cyanogenmod/filemanager/activities/PickerActivity.java
+++ b/src/com/cyanogenmod/filemanager/activities/PickerActivity.java
@@ -153,10 +153,6 @@ public class PickerActivity extends Activity
Log.d(TAG, "PickerActivity.onCreate"); //$NON-NLS-1$
}
- // Set the theme before setContentView
- Theme theme = ThemeManager.getCurrentTheme(this);
- theme.setBaseTheme(this, true);
-
//Save state
super.onCreate(state);
diff --git a/src/com/cyanogenmod/filemanager/service/MoveFileService.java b/src/com/cyanogenmod/filemanager/service/MoveFileService.java
new file mode 100644
index 00000000..21decfd1
--- /dev/null
+++ b/src/com/cyanogenmod/filemanager/service/MoveFileService.java
@@ -0,0 +1,192 @@
+/*
+* Copyright (C) 2015 The CyanogenMod Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package com.cyanogenmod.filemanager.service;
+
+import android.app.IntentService;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.os.AsyncTask;
+import android.util.Log;
+
+import com.cyanogenmod.filemanager.R;
+import com.cyanogenmod.filemanager.util.CommandHelper;
+
+import java.io.File;
+
+public class MoveFileService extends IntentService {
+ private static final String TAG = MoveFileService.class.getSimpleName();
+
+ private static final String FILE_MANAGER_PACKAGE = "com.cyanogenmod.filemanager";
+ private static final String FILE_MANAGER_ACTIVITY =
+ FILE_MANAGER_PACKAGE + ".activities.MainActivity";
+ private static final String EXTRA_NAVIGATE_TO = "extra_navigate_to";
+
+ public static final String EXTRA_SOURCE_FILE_PATH = "extra_source_file_path";
+ public static final String EXTRA_DESTINATION_FILE_PATH = "extra_destination_file_path";
+
+ private static final String TAG_SEPARATOR = ":::";
+
+ public MoveFileService() {
+ super(TAG);
+ }
+
+ @Override
+ protected void onHandleIntent(Intent intent) {
+ if (!intent.hasExtra(EXTRA_SOURCE_FILE_PATH)) {
+ Log.w(TAG, "Source file path not provided");
+ return;
+ }
+ if (!intent.hasExtra(EXTRA_DESTINATION_FILE_PATH)) {
+ Log.w(TAG, "Destination file path not provided");
+ return;
+ }
+ String srcPath = intent.getStringExtra(EXTRA_SOURCE_FILE_PATH);
+ String dstPath = intent.getStringExtra(EXTRA_DESTINATION_FILE_PATH);
+ String tag = getTagForNotification(srcPath, dstPath);
+
+ showMovingNotification(tag);
+ new MoveFileTask().execute(srcPath, dstPath);
+ }
+
+ /**
+ * Post the moving file notification
+ * @param tag Tag for identifying this notification
+ */
+ private void showMovingNotification(String tag) {
+ NotificationManager nm = NotificationManager.from(this);
+ Notification.Builder builder = new Notification.Builder(this);
+ builder.setContentTitle(getString(R.string.moving_file_notification_title));
+ builder.setSmallIcon(R.drawable.ic_object_move);
+ builder.setProgress(0, 100, true);
+ nm.notify(tag, 0, builder.build());
+ }
+
+ /**
+ * Post the file moved notification with a "show" action
+ * @param tag Tag for identifying this notification
+ * @param directoryPath Path to the moved file's parent directory
+ */
+ private void showFileMovedNotification(String tag, String directoryPath) {
+ NotificationManager nm = NotificationManager.from(this);
+ Notification.Builder builder = new Notification.Builder(this);
+ builder.setContentTitle(getString(R.string.move_complete_notification_title));
+ builder.setContentText(getString(R.string.move_complete_notification_description));
+ builder.setSmallIcon(R.drawable.ic_object_move);
+
+ // Add the show content intent
+ Intent intent = createFileManagerNavigateToIntent(directoryPath);
+ PendingIntent pi = PendingIntent.getActivity(this, 0, intent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ builder.setContentIntent(pi);
+ nm.notify(tag, 0, builder.build());
+ }
+
+ /**
+ * Post the move failed notification
+ * @param tag Tag for identifying this notification
+ * @param textResId String resource ID for the content text
+ */
+ private void showFileMoveFailedNotification(String tag, int textResId) {
+ NotificationManager nm = NotificationManager.from(this);
+ Notification.Builder builder = new Notification.Builder(this);
+ builder.setSmallIcon(R.drawable.ic_object_move);
+ builder.setContentTitle(getString(R.string.moving_file_failed_notification_title));
+ if (textResId > 0) builder.setContentText(getString(textResId));
+
+ // TODO: Add the retry action
+ nm.notify(tag, 0, builder.build());
+ }
+
+ /**
+ * Creates the intent used to show the folder containing the moved file
+ * @param filePath Absolute path to the moved file
+ * @return
+ */
+ private Intent createFileManagerNavigateToIntent(String filePath) {
+ File downloadedFile = new File(filePath);
+ String path = downloadedFile.getParent();
+ Intent intent = new Intent();
+ intent.setComponent(new ComponentName(FILE_MANAGER_PACKAGE, FILE_MANAGER_ACTIVITY));
+ intent.putExtra(EXTRA_NAVIGATE_TO, path);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+ return intent;
+ }
+
+ /**
+ * Creates a tag based on the source and destination paths
+ * @param srcPath Path to the file to be moved
+ * @param dstPath Path to the destination of the moved file
+ * @return Tag for use in posting a notification
+ */
+ private static String getTagForNotification(String srcPath, String dstPath) {
+ return srcPath + TAG_SEPARATOR + dstPath;
+ }
+
+ /**
+ * Extract the source path from the given tag
+ * @param tag
+ * @return
+ */
+ private static String getSourcePathFromTag(String tag) {
+ if (tag == null) {
+ throw new IllegalArgumentException("getSourcePathFromTag: Tag must be non-null");
+ }
+ return tag.substring(0, tag.indexOf(TAG_SEPARATOR));
+ }
+
+ private static String getDestinationPathFromTag(String tag) {
+ if (tag == null) {
+ throw new IllegalArgumentException("getDestinationPathFromTag: Tag must be non-null");
+ }
+
+ return tag.substring(tag.indexOf(TAG_SEPARATOR) + 1);
+ }
+
+ class MoveFileTask extends AsyncTask<String, Integer, Boolean> {
+ private String mSrcPath;
+ private String mDstPath;
+
+ @Override
+ protected Boolean doInBackground(String... params) {
+ mSrcPath = params[0];
+ mDstPath = params[1];
+ String fileName = mSrcPath.substring(mSrcPath.lastIndexOf(File.separator) + 1);
+ try {
+ CommandHelper.move(MoveFileService.this, mSrcPath, mDstPath, fileName, null, null);
+ } catch (Exception e) {
+ return Boolean.FALSE;
+ }
+
+ return Boolean.TRUE;
+ }
+
+ @Override
+ protected void onPostExecute(Boolean result) {
+ if (Boolean.TRUE.equals(result)) {
+ showFileMovedNotification(getTagForNotification(mSrcPath, mDstPath), mDstPath);
+ } else {
+ // TODO: store error type so we can show the appropriate notification
+ showFileMoveFailedNotification(getTagForNotification(mSrcPath, mDstPath),
+ R.string.moving_file_failed_generic);
+ }
+ }
+ }
+}