From 993fa8777d5f74af126d42baba25eed1cb9b19ba Mon Sep 17 00:00:00 2001 From: David Development Date: Fri, 6 Jun 2014 09:22:22 +0200 Subject: [PATCH] move to submodule --- .../ImportAccountsDialogFragment.java | 95 ------------- .../ListView/AccountImporterAdapter.java | 113 ---------------- .../helper/AccountImporter.java | 125 ------------------ .../helper/CheckableLinearLayout.java | 53 -------- .../interfaces/IAccountImport.java | 11 -- .../res/layout/import_accounts_fragment.xml | 23 ---- .../layout/simple_list_item_single_choice.xml | 74 ----------- 7 files changed, 494 deletions(-) delete mode 100644 News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ImportAccountsDialogFragment.java delete mode 100644 News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/AccountImporterAdapter.java delete mode 100644 News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/AccountImporter.java delete mode 100644 News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/CheckableLinearLayout.java delete mode 100644 News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/interfaces/IAccountImport.java delete mode 100644 News-Android-App/src/main/res/layout/import_accounts_fragment.xml delete mode 100644 News-Android-App/src/main/res/layout/simple_list_item_single_choice.xml diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ImportAccountsDialogFragment.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ImportAccountsDialogFragment.java deleted file mode 100644 index 40c70d97..00000000 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ImportAccountsDialogFragment.java +++ /dev/null @@ -1,95 +0,0 @@ -package de.luhmer.owncloudnewsreader; - -import android.accounts.Account; -import android.annotation.TargetApi; -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.DialogInterface; -import android.os.Build; -import android.os.Bundle; -import android.support.v4.app.DialogFragment; -import android.view.View; -import android.widget.Checkable; -import android.widget.ListView; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Pattern; - -import butterknife.ButterKnife; -import butterknife.InjectView; -import de.luhmer.owncloudnewsreader.ListView.AccountImporterAdapter; -import de.luhmer.owncloudnewsreader.helper.AccountImporter; -import de.luhmer.owncloudnewsreader.interfaces.IAccountImport; - -/** - * Created by David on 16.05.2014. - */ -@TargetApi(Build.VERSION_CODES.HONEYCOMB) -public class ImportAccountsDialogFragment extends DialogFragment { - - public IAccountImport accountImport; - - static ImportAccountsDialogFragment newInstance() { - return new ImportAccountsDialogFragment(); - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - View view = getActivity().getLayoutInflater().inflate(R.layout.import_accounts_fragment, null); - ButterKnife.inject(this, view); - - accountImport = LoginDialogFragment.getInstance(); - - - final List accounts = AccountImporter.findAccounts(getActivity()); - List accountList = new ArrayList(); - for(Account account : accounts) - accountList.add(new AccountImporterAdapter.SingleAccount(account.type, account.name, false)); - - //lvAccounts.setAdapter(new ArrayAdapter(getActivity(), R.layout.simple_list_item_single_choice, accountNames)); - lvAccounts.setAdapter(new AccountImporterAdapter(getActivity(), accountList.toArray(new AccountImporterAdapter.SingleAccount[accountList.size()]), lvAccounts)); - - lvAccounts.setItemsCanFocus(false); - lvAccounts.setChoiceMode(ListView.CHOICE_MODE_SINGLE); - - - return new AlertDialog.Builder(getActivity()) - .setView(view) - .setTitle(R.string.import_account_dialog_title) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int x) { - - for (int i = 0; i < lvAccounts.getAdapter().getCount(); i++) { - if (lvAccounts.getChildAt(i) instanceof Checkable && ((Checkable) lvAccounts.getChildAt(i)).isChecked()) { - - AccountImporter.getAuthTokenForAccount(getActivity(), accounts.get(i), accountImport); - - /* - Intent intent = new Intent(getActivity(), LoginActivity.class); - //intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); - intent.putExtra(LoginActivity.NEW_ACCOUNT, true); - intent.putExtra(URL_STRING, calendars.get(i)); - intent.putExtra(USERNAME_STRING, username); - intent.putExtra(PASSWORD_STRING, password); - startActivity(intent); - */ - } - } - } - }) - .setNegativeButton(android.R.string.no, null) - .create(); - } - - - @InjectView(R.id.lvAccounts) ListView lvAccounts; - //@InjectView(R.id.pbProgress) ProgressBar pbProgress; - - static final Pattern RemoveAllDoubleSlashes = Pattern.compile("(? implements AdapterView.OnItemClickListener { - - Context context; - //SingleAccount[] accounts; - LayoutInflater inflater; - - public AccountImporterAdapter(Activity context, SingleAccount[] accounts, ListView listView) { - super(context, R.layout.simple_list_item_single_choice, accounts); - this.context = context; - - listView.setOnItemClickListener(this); - - inflater = context.getLayoutInflater(); - } - - @Override - public View getView(final int position, View view, ViewGroup parent) { - ViewHolder holder; - - if (view != null) { - holder = (ViewHolder) view.getTag(); - } else { - view = inflater.inflate(R.layout.simple_list_item_single_choice, parent, false); - holder = new ViewHolder(view); - - /* - holder.cbChecked.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - if(compoundButton.isChecked()) { - for (int i = 0; i < getCount(); i++) { - getItem(i).checked = false; - } - getItem(position).checked = true; - notifyDataSetChanged(); - } - } - }); - */ - - view.setTag(holder); - } - - holder.text1.setText(getItem(position).type); - holder.text2.setText(getItem(position).url); - holder.cbChecked.setChecked(getItem(position).checked); - - - return view; - } - - @Override - public void onItemClick(AdapterView adapterView, View view, int id, long l) { - for (int i = 0; i < getCount(); i++) { - getItem(i).checked = false; - } - ((CheckableLinearLayout)view).toggle(); - - notifyDataSetChanged(); - } - - - - static class ViewHolder { - @InjectView(R.id.text1) TextView text1; - @InjectView(R.id.text2) TextView text2; - @InjectView(R.id.checkbox) CheckBox cbChecked; - - public ViewHolder(View view) { - ButterKnife.inject(this, view); - } - } - - - - - - public static class SingleAccount { - - public SingleAccount(String type, String url, Boolean checked) { - this.type = type; - this.url = url; - this.checked = checked; - } - - public String type; - public String url; - - public boolean checked; - } - -} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/AccountImporter.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/AccountImporter.java deleted file mode 100644 index 495a0610..00000000 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/AccountImporter.java +++ /dev/null @@ -1,125 +0,0 @@ -package de.luhmer.owncloudnewsreader.helper; - -import android.accounts.Account; -import android.accounts.AccountManager; -import android.accounts.AccountManagerCallback; -import android.accounts.AccountManagerFuture; -import android.accounts.OperationCanceledException; -import android.app.Activity; -import android.app.AlertDialog; -import android.os.Bundle; -import android.os.Handler; - -import java.util.ArrayList; -import java.util.List; - -import de.luhmer.owncloudnewsreader.interfaces.IAccountImport; - -/** - * Created by david on 28.05.14. - */ -public class AccountImporter { - - public static List findAccounts(Activity activity) { - final AccountManager accMgr = AccountManager.get(activity); - final Account[] accounts = accMgr.getAccounts(); - - List accountsAvailable = new ArrayList(); - for (Account account : accounts) { - String aType = account.type.intern(); - - if (//aType.equals("org.dmfs.caldav.account") || - // aType.equals("org.dmfs.carddav.account") || - aType.equals("de.luhmer.tasksync") || - aType.equals("owncloud")) { - //accountsAvailable.add(accounts[index].type); - accountsAvailable.add(account); - } - } - - return accountsAvailable; - } - - - - - public static void getAuthTokenForAccount(Activity activity, final Account account, final IAccountImport accountImport) { - - - final AccountManager accMgr = AccountManager.get(activity); - /* - accMgr.getAuthToken(account, AccountGeneral.ACCOUNT_TYPE, null, activity, new AccountManagerCallback() { - public void run(AccountManagerFuture future) { - try { - // If the user has authorized your application to use the tasks API - // a token is available. - String token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN); - // Now you can use the Tasks API... - if(accountImport != null) { - accountImport.accountAccessGranted(account, token); - } - } catch (OperationCanceledException e) { - e.printStackTrace(); - // TODO: The user has denied you access to the API, you should handle that - } catch (Exception e) { - e.printStackTrace(); - } - } - }, null); - */ - - - /* - if(accountImport != null) { - accountImport.accountAccessGranted(account, null); - } - */ - - //accMgr.invalidateAuthToken(account.type, AccountGeneral.ACCOUNT_TYPE); - //accMgr.invalidateAuthToken(account.type, null); - - final AlertDialog aDialog = new AlertDialog.Builder(activity) - .setTitle("Account Importer") - .setMessage("Please grant access to the selected account in the notification bar!") - .create(); - - aDialog.show(); - - String authTokenType; - if(account.type.equals("owncloud")) { - authTokenType = "owncloud.password"; - } else { - authTokenType = "de.luhmer.tasksync"; - } - - - final Handler handler = new Handler(); - accMgr.getAuthToken(account, authTokenType, true, - new AccountManagerCallback() { - - @Override - public void run(AccountManagerFuture future) { - - try { - // If the user has authorized your application to use the tasks API - // a token is available. - //String token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN); - // Now you can use the Tasks API... - if(accountImport != null) { - accountImport.accountAccessGranted(account, future.getResult()); - } - } catch (OperationCanceledException e) { - e.printStackTrace(); - // TODO: The user has denied you access to the API, you should handle that - } catch (Exception e) { - e.printStackTrace(); - } - - aDialog.dismiss(); - - } - }, handler - - ); - } -} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/CheckableLinearLayout.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/CheckableLinearLayout.java deleted file mode 100644 index 45369aca..00000000 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/CheckableLinearLayout.java +++ /dev/null @@ -1,53 +0,0 @@ -package de.luhmer.owncloudnewsreader.helper; - - -import android.content.Context; -import android.util.AttributeSet; -import android.view.View; -import android.widget.CheckBox; -import android.widget.Checkable; -import android.widget.LinearLayout; - -/** - * Created by David on 29.05.2014. - */ - -public class CheckableLinearLayout extends LinearLayout implements Checkable { - private CheckBox _checkbox; - - public CheckableLinearLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - // find checked text view - int childCount = getChildCount(); - for (int i = 0; i < childCount; ++i) { - View v = getChildAt(i); - if (v instanceof CheckBox) { - _checkbox = (CheckBox)v; - } - } - } - - @Override - public boolean isChecked() { - return _checkbox != null ? _checkbox.isChecked() : false; - } - - @Override - public void setChecked(boolean checked) { - if (_checkbox != null) { - _checkbox.setChecked(checked); - } - } - - @Override - public void toggle() { - if (_checkbox != null) { - _checkbox.toggle(); - } - } -} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/interfaces/IAccountImport.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/interfaces/IAccountImport.java deleted file mode 100644 index 0d8f772c..00000000 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/interfaces/IAccountImport.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.luhmer.owncloudnewsreader.interfaces; - -import android.accounts.Account; -import android.os.Bundle; - -/** - * Created by David on 28.05.2014. - */ -public interface IAccountImport { - public void accountAccessGranted(Account account, Bundle data); -} diff --git a/News-Android-App/src/main/res/layout/import_accounts_fragment.xml b/News-Android-App/src/main/res/layout/import_accounts_fragment.xml deleted file mode 100644 index 97e8fc73..00000000 --- a/News-Android-App/src/main/res/layout/import_accounts_fragment.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/News-Android-App/src/main/res/layout/simple_list_item_single_choice.xml b/News-Android-App/src/main/res/layout/simple_list_item_single_choice.xml deleted file mode 100644 index 01cc2ded..00000000 --- a/News-Android-App/src/main/res/layout/simple_list_item_single_choice.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file