Anthony Restaino
10 years ago
13 changed files with 380 additions and 78 deletions
@ -0,0 +1,91 @@
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical" > |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/exportBackup" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="60dp" |
||||
android:background="?android:attr/listChoiceBackgroundIndicator" |
||||
android:gravity="center_vertical" |
||||
android:orientation="vertical" |
||||
android:paddingBottom="10dp" |
||||
android:paddingTop="10dp" > |
||||
|
||||
<TextView |
||||
android:id="@+id/textView1" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:paddingLeft="10dp" |
||||
android:text="@string/export_bookmarks" |
||||
android:textAppearance="?android:attr/textAppearanceMedium" /> |
||||
</LinearLayout> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="1dp" |
||||
android:layout_marginLeft="5dp" |
||||
android:layout_marginRight="5dp" |
||||
android:background="#cdcdcd" /> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/importBackup" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="60dp" |
||||
android:background="?android:attr/listChoiceBackgroundIndicator" |
||||
android:gravity="center_vertical" |
||||
android:orientation="vertical" |
||||
android:paddingBottom="10dp" |
||||
android:paddingTop="10dp" > |
||||
|
||||
<TextView |
||||
android:id="@+id/textView2" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:paddingLeft="10dp" |
||||
android:text="@string/import_backup" |
||||
android:textAppearance="?android:attr/textAppearanceMedium" /> |
||||
</LinearLayout> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="1dp" |
||||
android:layout_marginLeft="5dp" |
||||
android:layout_marginRight="5dp" |
||||
android:background="#cdcdcd" /> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/importFromBrowser" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="60dp" |
||||
android:background="?android:attr/listChoiceBackgroundIndicator" |
||||
android:gravity="center_vertical" |
||||
android:orientation="vertical" > |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:paddingLeft="10dp" |
||||
android:text="@string/importbookmarks" |
||||
android:textAppearance="?android:attr/textAppearanceMedium" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/isImportBrowserAvailable" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:paddingLeft="10dp" |
||||
android:text="@string/recommended" |
||||
android:textAppearance="?android:attr/textAppearanceSmall" |
||||
android:textColor="@color/light" /> |
||||
</LinearLayout> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="1dp" |
||||
android:layout_marginLeft="5dp" |
||||
android:layout_marginRight="5dp" |
||||
android:background="#cdcdcd" /> |
||||
|
||||
</LinearLayout> |
@ -0,0 +1,175 @@
@@ -0,0 +1,175 @@
|
||||
package acr.browser.lightning; |
||||
|
||||
import java.io.File; |
||||
import java.util.Arrays; |
||||
import java.util.Comparator; |
||||
|
||||
import android.app.ActionBar; |
||||
import android.app.Activity; |
||||
import android.app.AlertDialog; |
||||
import android.app.AlertDialog.Builder; |
||||
import android.app.Dialog; |
||||
import android.content.DialogInterface; |
||||
import android.content.SharedPreferences; |
||||
import android.os.Bundle; |
||||
import android.os.Environment; |
||||
import android.view.MenuItem; |
||||
import android.view.View; |
||||
import android.view.View.OnClickListener; |
||||
import android.widget.LinearLayout; |
||||
import android.widget.TextView; |
||||
|
||||
public class BookmarkActivity extends Activity implements OnClickListener { |
||||
|
||||
private BookmarkManager mBookmarkManager; |
||||
private boolean mSystemBrowser; |
||||
private SharedPreferences mPreferences; |
||||
private File[] mFileList; |
||||
private String[] mFileNameList; |
||||
private File mPath = new File(Environment.getExternalStorageDirectory().toString()); |
||||
private static final int DIALOG_LOAD_FILE = 1000; |
||||
|
||||
@Override |
||||
public void onCreate(Bundle savedInstanceState) { |
||||
super.onCreate(savedInstanceState); |
||||
|
||||
setContentView(R.layout.bookmark_activity); |
||||
|
||||
ActionBar actionBar = getActionBar(); |
||||
if (actionBar != null) { |
||||
actionBar.setHomeButtonEnabled(true); |
||||
actionBar.setDisplayHomeAsUpEnabled(true); |
||||
} |
||||
|
||||
LinearLayout exportBackup = (LinearLayout) findViewById(R.id.exportBackup); |
||||
LinearLayout importBackup = (LinearLayout) findViewById(R.id.importBackup); |
||||
LinearLayout importFromBrowser = (LinearLayout) findViewById(R.id.importFromBrowser); |
||||
|
||||
TextView importBookmarks = (TextView) findViewById(R.id.isImportBrowserAvailable); |
||||
|
||||
mBookmarkManager = new BookmarkManager(this); |
||||
|
||||
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); |
||||
|
||||
mSystemBrowser = mPreferences.getBoolean(PreferenceConstants.SYSTEM_BROWSER_PRESENT, false); |
||||
|
||||
exportBackup.setOnClickListener(this); |
||||
importBackup.setOnClickListener(this); |
||||
importFromBrowser.setOnClickListener(this); |
||||
|
||||
if (mSystemBrowser) { |
||||
importBookmarks.setText(getResources().getString(R.string.stock_browser_available)); |
||||
} else { |
||||
importBookmarks.setText(getResources().getString(R.string.stock_browser_unavailable)); |
||||
} |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void onClick(View v) { |
||||
switch (v.getId()) { |
||||
case R.id.importBackup: |
||||
loadFileList(null); |
||||
onCreateDialog(DIALOG_LOAD_FILE); |
||||
break; |
||||
case R.id.importFromBrowser: |
||||
mBookmarkManager.importBookmarksFromBrowser(); |
||||
break; |
||||
case R.id.exportBackup: |
||||
mBookmarkManager.exportBookmarks(); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public boolean onOptionsItemSelected(MenuItem item) { |
||||
finish(); |
||||
return true; |
||||
} |
||||
|
||||
private void loadFileList(File path) { |
||||
File file; |
||||
if (path != null) { |
||||
file = path; |
||||
} else { |
||||
file = mPath; |
||||
} |
||||
try { |
||||
file.mkdirs(); |
||||
} catch (SecurityException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
if (file.exists()) { |
||||
mFileList = file.listFiles(); |
||||
} else { |
||||
mFileList = new File[0]; |
||||
} |
||||
|
||||
Arrays.sort(mFileList, new SortFileName()); |
||||
Arrays.sort(mFileList, new SortFolders()); |
||||
|
||||
if (mFileList == null) { |
||||
mFileNameList = new String[0]; |
||||
mFileList = new File[0]; |
||||
} else { |
||||
mFileNameList = new String[mFileList.length]; |
||||
} |
||||
for (int n = 0; n < mFileList.length; n++) { |
||||
mFileNameList[n] = mFileList[n].getName(); |
||||
} |
||||
} |
||||
|
||||
protected Dialog onCreateDialog(int id) { |
||||
Dialog dialog = null; |
||||
final AlertDialog.Builder builder = new Builder(this); |
||||
|
||||
switch (id) { |
||||
case DIALOG_LOAD_FILE: |
||||
builder.setTitle(R.string.title_chooser); |
||||
if (mFileList == null) { |
||||
dialog = builder.create(); |
||||
return dialog; |
||||
} |
||||
builder.setItems(mFileNameList, new DialogInterface.OnClickListener() { |
||||
|
||||
@Override |
||||
public void onClick(DialogInterface dialog, int which) { |
||||
if (mFileList[which].isDirectory()) { |
||||
loadFileList(mFileList[which]); |
||||
builder.setItems(mFileNameList, this); |
||||
builder.show(); |
||||
} else { |
||||
mBookmarkManager.importBookmarksFromFile(mFileList[which]); |
||||
} |
||||
} |
||||
|
||||
}); |
||||
break; |
||||
} |
||||
dialog = builder.show(); |
||||
return dialog; |
||||
} |
||||
|
||||
public class SortFileName implements Comparator<File> { |
||||
|
||||
@Override |
||||
public int compare(File f1, File f2) { |
||||
return f1.getName().compareTo(f2.getName()); |
||||
} |
||||
|
||||
} |
||||
|
||||
public class SortFolders implements Comparator<File> { |
||||
|
||||
@Override |
||||
public int compare(File f1, File f2) { |
||||
if (f1.isDirectory() == f2.isDirectory()) |
||||
return 0; |
||||
else if (f1.isDirectory() && !f2.isDirectory()) |
||||
return -1; |
||||
else |
||||
return 1; |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue