List of usage examples for android.content Intent ACTION_MAIN
String ACTION_MAIN
To view the source code for android.content Intent ACTION_MAIN.
Click Source Link
From source file:activities.PaintActivity.java
@Override public void onBackPressed() { if (backButtonCount >= 1) { if (toast != null) toast.cancel();/*from w w w .ja v a2s . c o m*/ toast = null; Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); backButtonCount = 0; } else { toast = Toast.makeText(this, "Press the back button once again to close the application.", Toast.LENGTH_LONG); toast.show(); backButtonCount++; } }
From source file:com.nbplus.vbroadlauncher.HomeLauncherActivity.java
/** @Override// www . j a va 2s . com protected void onNewIntent(Intent intent) { //super.onNewIntent(intent); if (intent == null) { return; } String action = intent.getAction(); Log.d(TAG, "onNewIntent.. action = " + action); // if (PushConstants.ACTION_PUSH_STATUS_CHANGED.equals(action) || PushConstants.ACTION_PUSH_MESSAGE_RECEIVED.equals(action)) { // setPushServiceStatus(intent.getIntExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE, PushConstants.PUSH_STATUS_VALUE_DISCONNECTED)); // // if (mActivityInteractionListener != null) { // for (OnActivityInteractionListener listener : mActivityInteractionListener) { // listener.onPushReceived(intent); // } // } // } } */ protected boolean isMyLauncherDefault() { final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN); filter.addCategory(Intent.CATEGORY_HOME); List<IntentFilter> filters = new ArrayList<IntentFilter>(); filters.add(filter); final String myPackageName = getPackageName(); List<ComponentName> activities = new ArrayList<ComponentName>(); final PackageManager packageManager = (PackageManager) getPackageManager(); // You can use name of your package here as third argument packageManager.getPreferredActivities(filters, activities, null); for (ComponentName activity : activities) { if (myPackageName.equals(activity.getPackageName())) { return true; } } return false; }
From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java
/** * Shows a list of primary user apps in a dialog. * * @param dialogTitle the title to show for the dialog * @param callback will be called with the list apps that the user has selected when he closes * the dialog. The callback is not fired if the user cancels. *///from www. j a v a 2 s . c o m private void showManageLockTaskListPrompt(int dialogTitle, final ManageLockTaskListCallback callback) { if (getActivity() == null || getActivity().isFinishing()) { return; } Intent launcherIntent = new Intent(Intent.ACTION_MAIN); launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER); final List<ResolveInfo> primaryUserAppList = mPackageManager.queryIntentActivities(launcherIntent, 0); if (primaryUserAppList.isEmpty()) { showToast(R.string.no_primary_app_available); } else { Collections.sort(primaryUserAppList, new ResolveInfo.DisplayNameComparator(mPackageManager)); final LockTaskAppInfoArrayAdapter appInfoArrayAdapter = new LockTaskAppInfoArrayAdapter(getActivity(), R.id.pkg_name, primaryUserAppList); ListView listView = new ListView(getActivity()); listView.setAdapter(appInfoArrayAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { appInfoArrayAdapter.onItemClick(parent, view, position, id); } }); new AlertDialog.Builder(getActivity()).setTitle(getString(dialogTitle)).setView(listView) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String[] lockTaskEnabledArray = appInfoArrayAdapter.getLockTaskList(); callback.onPositiveButtonClicked(lockTaskEnabledArray); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); } }
From source file:org.thecongers.mtpms.MainActivity.java
private void Notify(String notificationMessage) { notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Intent intent = new Intent(this, MainActivity.class); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); String alertURI = sharedPrefs.getString("prefsound", "content://settings/system/notification_sound"); Uri soundURI = Uri.parse(alertURI);//from ww w. ja va 2 s. com // Build notification NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(getResources().getString(R.string.app_shortName)) .setContentText(notificationMessage).setSmallIcon(R.drawable.notification_icon).setAutoCancel(false) .setOnlyAlertOnce(true).setPriority(Notification.PRIORITY_MAX).setContentIntent(pendingIntent); // Check for LED enabled if (sharedPrefs.getBoolean("prefNotificationLED", true)) { builder.setLights(android.graphics.Color.RED, 1500, 1500); } // Check for sound enabled if (sharedPrefs.getBoolean("prefNotificationSound", true)) { builder.setSound(soundURI); } Notification notification = builder.build(); // Check for vibration enabled if (sharedPrefs.getBoolean("prefNotificationVibrate", false)) { notification.defaults |= Notification.DEFAULT_VIBRATE; } // Make alert repeat until read notification.flags |= Notification.FLAG_INSISTENT; // Send notification notificationManager.notify(0, notification); }
From source file:com.ichi2.anki2.DeckPicker.java
/** Called when the activity is first created. */ @Override/* w w w . jav a2s . com*/ protected void onCreate(Bundle savedInstanceState) throws SQLException { Log.i(AnkiDroidApp.TAG, "DeckPicker - onCreate"); Intent intent = getIntent(); if (!isTaskRoot()) { Log.i(AnkiDroidApp.TAG, "DeckPicker - onCreate: Detected multiple instance of this activity, closing it and return to root activity"); Intent reloadIntent = new Intent(DeckPicker.this, DeckPicker.class); reloadIntent.setAction(Intent.ACTION_MAIN); if (intent != null && intent.getExtras() != null) { reloadIntent.putExtras(intent.getExtras()); } if (intent != null && intent.getData() != null) { reloadIntent.setData(intent.getData()); } reloadIntent.addCategory(Intent.CATEGORY_LAUNCHER); reloadIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); finish(); startActivityIfNeeded(reloadIntent, 0); } if (intent.getData() != null) { mImportPath = getIntent().getData().getEncodedPath(); } // need to start this here in order to avoid showing deckpicker before splashscreen if (AnkiDroidApp.colIsOpen()) { setTitle(getResources().getString(R.string.app_name)); } else { setTitle(""); mOpenCollectionHandler.onPreExecute(); } Themes.applyTheme(this); super.onCreate(savedInstanceState); // mStartedByBigWidget = intent.getIntExtra(EXTRA_START, EXTRA_START_NOTHING); SharedPreferences preferences = restorePreferences(); // activate broadcast messages if first start of a day if (mLastTimeOpened < UIUtils.getDayStart()) { preferences.edit().putBoolean("showBroadcastMessageToday", true).commit(); } preferences.edit().putLong("lastTimeOpened", System.currentTimeMillis()).commit(); // if (intent != null && intent.hasExtra(EXTRA_DECK_ID)) { // openStudyOptions(intent.getLongExtra(EXTRA_DECK_ID, 1)); // } BroadcastMessages.checkForNewMessages(this); View mainView = getLayoutInflater().inflate(R.layout.deck_picker, null); setContentView(mainView); // check, if tablet layout View studyoptionsFrame = findViewById(R.id.studyoptions_fragment); mFragmented = studyoptionsFrame != null && studyoptionsFrame.getVisibility() == View.VISIBLE; Themes.setContentStyle(mFragmented ? mainView : mainView.findViewById(R.id.deckpicker_view), Themes.CALLER_DECKPICKER); registerExternalStorageListener(); if (!mFragmented) { mAddButton = (ImageButton) findViewById(R.id.deckpicker_add); mAddButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { addNote(); } }); mCardsButton = (ImageButton) findViewById(R.id.deckpicker_card_browser); mCardsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { openCardBrowser(); } }); mStatsButton = (ImageButton) findViewById(R.id.statistics_all_button); mStatsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showDialog(DIALOG_SELECT_STATISTICS_TYPE); } }); mSyncButton = (ImageButton) findViewById(R.id.sync_all_button); mSyncButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { sync(); } }); } mInvalidateMenu = false; mDeckList = new ArrayList<HashMap<String, String>>(); mDeckListView = (ListView) findViewById(R.id.files); mDeckListAdapter = new SimpleAdapter(this, mDeckList, R.layout.deck_item, new String[] { "name", "new", "lrn", "rev", // "complMat", "complAll", "sep", "dyn" }, new int[] { R.id.DeckPickerName, R.id.deckpicker_new, R.id.deckpicker_lrn, R.id.deckpicker_rev, // R.id.deckpicker_bar_mat, R.id.deckpicker_bar_all, R.id.deckpicker_deck, R.id.DeckPickerName }); mDeckListAdapter.setViewBinder(new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object data, String text) { if (view.getId() == R.id.deckpicker_deck) { if (text.equals("top")) { view.setBackgroundResource(R.drawable.white_deckpicker_top); return true; } else if (text.equals("bot")) { view.setBackgroundResource(R.drawable.white_deckpicker_bottom); return true; } else if (text.equals("ful")) { view.setBackgroundResource(R.drawable.white_deckpicker_full); return true; } else if (text.equals("cen")) { view.setBackgroundResource(R.drawable.white_deckpicker_center); return true; } } else if (view.getId() == R.id.DeckPickerName) { if (text.equals("d0")) { ((TextView) view).setTextColor(getResources().getColor(R.color.non_dyn_deck)); return true; } else if (text.equals("d1")) { ((TextView) view).setTextColor(getResources().getColor(R.color.dyn_deck)); return true; } } // } else if (view.getId() == R.id.deckpicker_bar_mat || view.getId() == R.id.deckpicker_bar_all) { // if (text.length() > 0 && !text.equals("-1.0")) { // View parent = (View)view.getParent().getParent(); // if (text.equals("-2")) { // parent.setVisibility(View.GONE); // } else { // Utils.updateProgressBars(view, (int) UIUtils.getDensityAdjustedValue(DeckPicker.this, 3.4f), // (int) (Double.parseDouble(text) * ((View)view.getParent().getParent().getParent()).getHeight())); // if (parent.getVisibility() == View.INVISIBLE) { // parent.setVisibility(View.VISIBLE); // parent.setAnimation(ViewAnimation.fade(ViewAnimation.FADE_IN, 500, 0)); // } // } // } // return true; // } else if (view.getVisibility() == View.INVISIBLE) { // if (!text.equals("-1")) { // view.setVisibility(View.VISIBLE); // view.setAnimation(ViewAnimation.fade(ViewAnimation.FADE_IN, 500, 0)); // return false; // } // } else if (text.equals("-1")){ // view.setVisibility(View.INVISIBLE); // return false; return false; } }); mDeckListView.setOnItemClickListener(mDeckSelHandler); mDeckListView.setAdapter(mDeckListAdapter); if (mFragmented) { mDeckListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); } registerForContextMenu(mDeckListView); showStartupScreensAndDialogs(preferences, 0); if (mSwipeEnabled) { gestureDetector = new GestureDetector(new MyGestureDetector()); mDeckListView.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (gestureDetector.onTouchEvent(event)) { return true; } return false; } }); } }
From source file:com.findcab.activity.LocationOverlay.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (keyCode == KeyEvent.KEYCODE_BACK) { // exitDialog(context); //??home? Intent intents = new Intent(Intent.ACTION_MAIN); intents.addCategory(Intent.CATEGORY_HOME); intents.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intents);/*from w w w . j a v a 2 s . co m*/ } return super.onKeyDown(keyCode, event); }
From source file:com.nit.vicky.DeckPicker.java
/** Called when the activity is first created. */ @Override/*from w w w.java 2s . co m*/ protected void onCreate(Bundle savedInstanceState) throws SQLException { // Log.i(AnkiDroidApp.TAG, "DeckPicker - onCreate"); Intent intent = getIntent(); if (!isTaskRoot()) { // Log.i(AnkiDroidApp.TAG, "DeckPicker - onCreate: Detected multiple instance of this activity, closing it and return to root activity"); Intent reloadIntent = new Intent(DeckPicker.this, DeckPicker.class); reloadIntent.setAction(Intent.ACTION_MAIN); if (intent != null && intent.getExtras() != null) { reloadIntent.putExtras(intent.getExtras()); } if (intent != null && intent.getData() != null) { reloadIntent.setData(intent.getData()); } reloadIntent.addCategory(Intent.CATEGORY_LAUNCHER); reloadIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); finish(); startActivityIfNeeded(reloadIntent, 0); } if (intent.getData() != null) { mImportPath = getIntent().getData().getEncodedPath(); } // need to start this here in order to avoid showing deckpicker before splashscreen if (AnkiDroidApp.colIsOpen()) { setTitle(getResources().getString(R.string.app_name)); } else { setTitle(""); mOpenCollectionHandler.onPreExecute(); } Themes.applyTheme(this); super.onCreate(savedInstanceState); // mStartedByBigWidget = intent.getIntExtra(EXTRA_START, EXTRA_START_NOTHING); SharedPreferences preferences = restorePreferences(); // activate broadcast messages if first start of a day if (mLastTimeOpened < UIUtils.getDayStart()) { preferences.edit().putBoolean("showBroadcastMessageToday", true).commit(); } preferences.edit().putLong("lastTimeOpened", System.currentTimeMillis()).commit(); // if (intent != null && intent.hasExtra(EXTRA_DECK_ID)) { // openStudyOptions(intent.getLongExtra(EXTRA_DECK_ID, 1)); // } //BroadcastMessages.checkForNewMessages(this); View mainView = getLayoutInflater().inflate(R.layout.deck_picker, null); setContentView(mainView); // check, if tablet layout View studyoptionsFrame = findViewById(R.id.studyoptions_fragment); mFragmented = studyoptionsFrame != null && studyoptionsFrame.getVisibility() == View.VISIBLE; Themes.setContentStyle(mFragmented ? mainView : mainView.findViewById(R.id.deckpicker_view), Themes.CALLER_DECKPICKER); registerExternalStorageListener(); if (!mFragmented) { mAddButton = (ImageButton) findViewById(R.id.deckpicker_add); mAddButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { addNote(); } }); mCardsButton = (ImageButton) findViewById(R.id.deckpicker_card_browser); mCardsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { openCardBrowser(); } }); mStatsButton = (ImageButton) findViewById(R.id.statistics_all_button); mStatsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showDialog(DIALOG_SELECT_STATISTICS_TYPE); } }); mSyncButton = (ImageButton) findViewById(R.id.sync_all_button); mSyncButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { sync(); } }); } mInvalidateMenu = false; mDeckList = new ArrayList<HashMap<String, String>>(); mDeckListView = (ListView) findViewById(R.id.files); mDeckListAdapter = new SimpleAdapter(this, mDeckList, R.layout.deck_item, new String[] { "name", "new", "lrn", "rev", // "complMat", "complAll", "sep", "dyn" }, new int[] { R.id.DeckPickerName, R.id.deckpicker_new, R.id.deckpicker_lrn, R.id.deckpicker_rev, // R.id.deckpicker_bar_mat, R.id.deckpicker_bar_all, R.id.deckpicker_deck, R.id.DeckPickerName }); mDeckListAdapter.setViewBinder(new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object data, String text) { if (view.getId() == R.id.deckpicker_deck) { if (text.equals("top")) { view.setBackgroundResource(R.drawable.white_deckpicker_top); return true; } else if (text.equals("bot")) { view.setBackgroundResource(R.drawable.white_deckpicker_bottom); return true; } else if (text.equals("ful")) { view.setBackgroundResource(R.drawable.white_deckpicker_full); return true; } else if (text.equals("cen")) { view.setBackgroundResource(R.drawable.white_deckpicker_center); return true; } } else if (view.getId() == R.id.DeckPickerName) { if (text.equals("d0")) { ((TextView) view).setTextColor(getResources().getColor(R.color.non_dyn_deck)); return true; } else if (text.equals("d1")) { ((TextView) view).setTextColor(getResources().getColor(R.color.dyn_deck)); return true; } } // } else if (view.getId() == R.id.deckpicker_bar_mat || view.getId() == R.id.deckpicker_bar_all) { // if (text.length() > 0 && !text.equals("-1.0")) { // View parent = (View)view.getParent().getParent(); // if (text.equals("-2")) { // parent.setVisibility(View.GONE); // } else { // Utils.updateProgressBars(view, (int) UIUtils.getDensityAdjustedValue(DeckPicker.this, 3.4f), // (int) (Double.parseDouble(text) * ((View)view.getParent().getParent().getParent()).getHeight())); // if (parent.getVisibility() == View.INVISIBLE) { // parent.setVisibility(View.VISIBLE); // parent.setAnimation(ViewAnimation.fade(ViewAnimation.FADE_IN, 500, 0)); // } // } // } // return true; // } else if (view.getVisibility() == View.INVISIBLE) { // if (!text.equals("-1")) { // view.setVisibility(View.VISIBLE); // view.setAnimation(ViewAnimation.fade(ViewAnimation.FADE_IN, 500, 0)); // return false; // } // } else if (text.equals("-1")){ // view.setVisibility(View.INVISIBLE); // return false; return false; } }); mDeckListView.setOnItemClickListener(mDeckSelHandler); mDeckListView.setAdapter(mDeckListAdapter); if (mFragmented) { mDeckListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); } registerForContextMenu(mDeckListView); showStartupScreensAndDialogs(preferences, 0); if (mSwipeEnabled) { gestureDetector = new GestureDetector(new MyGestureDetector()); mDeckListView.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (gestureDetector.onTouchEvent(event)) { return true; } return false; } }); } }
From source file:co.taqat.call.LinphoneActivity.java
public void quit() { finish();/*from w w w .j ava 2s . c o m*/ stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class)); android.os.Process.killProcess(android.os.Process.myPid()); }
From source file:com.dycody.android.idealnote.ListFragment.java
public void toggleSearchLabel(boolean activate) { if (activate) { searchQueryView.setText(Html.fromHtml(getString(R.string.search) + ":<b> " + searchQuery + "</b>")); searchLayout.setVisibility(View.VISIBLE); searchCancel.setOnClickListener(v -> toggleSearchLabel(false)); searchLabelActive = true;/*from www. j av a 2 s . c o m*/ } else { if (searchLabelActive) { searchLabelActive = false; AnimationsHelper.expandOrCollapse(searchLayout, false); searchTags = null; searchQuery = null; if (!goBackOnToggleSearchLabel) { mainActivity.getIntent().setAction(Intent.ACTION_MAIN); if (searchView != null) { MenuItemCompat.collapseActionView(searchMenuItem); } initNotesList(mainActivity.getIntent()); } else { mainActivity.onBackPressed(); } goBackOnToggleSearchLabel = false; if (Intent.ACTION_VIEW.equals(mainActivity.getIntent().getAction())) { mainActivity.getIntent().setAction(null); } } } }
From source file:com.hichinaschool.flashcards.anki.DeckPicker.java
/** Called when the activity is first created. */ @Override//w w w . j a v a 2 s. c o m protected void onCreate(Bundle savedInstanceState) throws SQLException { // Log.i(AnkiDroidApp.TAG, "DeckPicker - onCreate"); Intent intent = getIntent(); if (!isTaskRoot()) { // Log.i(AnkiDroidApp.TAG, "DeckPicker - onCreate: Detected multiple instance of this activity, closing it and return to root activity"); Intent reloadIntent = new Intent(DeckPicker.this, DeckPicker.class); reloadIntent.setAction(Intent.ACTION_MAIN); if (intent != null && intent.getExtras() != null) { reloadIntent.putExtras(intent.getExtras()); } if (intent != null && intent.getData() != null) { reloadIntent.setData(intent.getData()); } reloadIntent.addCategory(Intent.CATEGORY_LAUNCHER); reloadIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); finish(); startActivityIfNeeded(reloadIntent, 0); } if (intent.getData() != null) { mImportPath = getIntent().getData().getEncodedPath(); } // need to start this here in order to avoid showing deckpicker before splashscreen if (AnkiDroidApp.colIsOpen()) { setTitle(getResources().getString(R.string.app_name)); } else { setTitle(""); mOpenCollectionHandler.onPreExecute(); } Themes.applyTheme(this); super.onCreate(savedInstanceState); // mStartedByBigWidget = intent.getIntExtra(EXTRA_START, EXTRA_START_NOTHING); SharedPreferences preferences = restorePreferences(); // activate broadcast messages if first start of a day if (mLastTimeOpened < UIUtils.getDayStart()) { preferences.edit().putBoolean("showBroadcastMessageToday", true).commit(); } preferences.edit().putLong("lastTimeOpened", System.currentTimeMillis()).commit(); // if (intent != null && intent.hasExtra(EXTRA_DECK_ID)) { // openStudyOptions(intent.getLongExtra(EXTRA_DECK_ID, 1)); // } // BroadcastMessages.checkForNewMessages(this); View mainView = getLayoutInflater().inflate(R.layout.deck_picker, null); setContentView(mainView); // check, if tablet layout View studyoptionsFrame = findViewById(R.id.studyoptions_fragment); mFragmented = studyoptionsFrame != null && studyoptionsFrame.getVisibility() == View.VISIBLE; Themes.setContentStyle(mFragmented ? mainView : mainView.findViewById(R.id.deckpicker_view), Themes.CALLER_DECKPICKER); registerExternalStorageListener(); if (!mFragmented) { // mAddButton = (ImageButton) findViewById(R.id.deckpicker_add); // mAddButton.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View v) { // addNote(); // } // }); // // mCardsButton = (ImageButton) findViewById(R.id.deckpicker_card_browser); // mCardsButton.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View v) { // openCardBrowser(); // } // }); // // mStatsButton = (ImageButton) findViewById(R.id.statistics_all_button); // mStatsButton.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View v) { // showDialog(DIALOG_SELECT_STATISTICS_TYPE); // } // }); // // mSyncButton = (ImageButton) findViewById(R.id.sync_all_button); // mSyncButton.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View v) { // sync(); // } // }); } mInvalidateMenu = false; mDeckList = new ArrayList<HashMap<String, String>>(); mDeckListView = (ListView) findViewById(R.id.files); // mDeckListAdapter = new SimpleAdapter(this, mDeckList, R.layout.deck_item, new String[] { "name", "new", "lrn", // "rev", // "complMat", "complAll", // "sep", "dyn" }, new int[] { R.id.DeckPickerName, R.id.deckpicker_new, R.id.deckpicker_lrn, // R.id.deckpicker_rev, // R.id.deckpicker_bar_mat, R.id.deckpicker_bar_all, // R.id.deckpicker_deck, R.id.DeckPickerName }); mDeckListAdapter = new SimpleAdapter(this, mDeckList, R.layout.deck_item, new String[] { "name", "new", "lrn", "rev", "sep", "dyn", "url" }, new int[] { R.id.DeckPickerName, R.id.deckpicker_new, R.id.deckpicker_lrn, R.id.deckpicker_rev, R.id.deckpicker_deck, R.id.DeckPickerName, R.id.deckpicker_url }); mDeckListAdapter.setViewBinder(new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(final View view, final Object data, String text) { if (view.getId() == R.id.deckpicker_url) { // If "url" field has text, it means the deck must be downloaded // so we put the downloadButton visible and add its listener if (!text.equals("")) { final View parentView = (View) view.getParent(); Button downloadButton = (Button) parentView.findViewById(R.id.deckpicker_button); downloadButton.setVisibility(View.VISIBLE); parentView.findViewById(R.id.deckpicker_new).setVisibility(View.GONE); parentView.findViewById(R.id.deckpicker_rev).setVisibility(View.GONE); parentView.findViewById(R.id.deckpicker_lrn).setVisibility(View.GONE); downloadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // ListView lv = (ListView) parentView.getParent().getParent(); // int i; // for (i = 0; i < mDeckList.size(); i++) { // if (mDeckListView.getItemAtPosition(i).equals(view)){ // mDeckLastItemSelected = i; // } // } // Gets url from the selected deck and download it TextView txt = (TextView) ((View) view.getParent()) .findViewById(R.id.deckpicker_url); String url = txt.getText().toString(); Connection.downloadSharedDeck(mDownloadDeckListener, new Connection.Payload(new Object[] { url })); } }); } else { Button downloadButton = (Button) ((View) view.getParent()) .findViewById(R.id.deckpicker_button); downloadButton.setVisibility(View.GONE); ((View) view.getParent()).findViewById(R.id.deckpicker_new).setVisibility(View.VISIBLE); ((View) view.getParent()).findViewById(R.id.deckpicker_rev).setVisibility(View.VISIBLE); ((View) view.getParent()).findViewById(R.id.deckpicker_lrn).setVisibility(View.VISIBLE); } } if (view.getId() == R.id.deckpicker_deck) { if (text.equals("top")) { view.setBackgroundResource(R.drawable.white_deckpicker_top); return true; } else if (text.equals("bot")) { view.setBackgroundResource(R.drawable.white_deckpicker_bottom); return true; } else if (text.equals("ful")) { view.setBackgroundResource(R.drawable.white_deckpicker_full); return true; } else if (text.equals("cen")) { view.setBackgroundResource(R.drawable.white_deckpicker_center); return true; } } else if (view.getId() == R.id.DeckPickerName) { if (text.equals("d0")) { ((TextView) view).setTextColor(getResources().getColor(R.color.non_dyn_deck)); return true; } else if (text.equals("d1")) { ((TextView) view).setTextColor(getResources().getColor(R.color.dyn_deck)); return true; } } // } else if (view.getId() == R.id.deckpicker_bar_mat || view.getId() == R.id.deckpicker_bar_all) { // if (text.length() > 0 && !text.equals("-1.0")) { // View parent = (View)view.getParent().getParent(); // if (text.equals("-2")) { // parent.setVisibility(View.GONE); // } else { // Utils.updateProgressBars(view, (int) UIUtils.getDensityAdjustedValue(DeckPicker.this, 3.4f), // (int) (Double.parseDouble(text) * ((View)view.getParent().getParent().getParent()).getHeight())); // if (parent.getVisibility() == View.INVISIBLE) { // parent.setVisibility(View.VISIBLE); // parent.setAnimation(ViewAnimation.fade(ViewAnimation.FADE_IN, 500, 0)); // } // } // } // return true; // } else if (view.getVisibility() == View.INVISIBLE) { // if (!text.equals("-1")) { // view.setVisibility(View.VISIBLE); // view.setAnimation(ViewAnimation.fade(ViewAnimation.FADE_IN, 500, 0)); // return false; // } // } else if (text.equals("-1")){ // view.setVisibility(View.INVISIBLE); // return false; return false; } }); mDeckListView.setOnItemClickListener(mDeckSelHandler); mDeckListView.setAdapter(mDeckListAdapter); if (mFragmented) { mDeckListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); } registerForContextMenu(mDeckListView); showStartupScreensAndDialogs(preferences, 0); if (mSwipeEnabled) { gestureDetector = new GestureDetector(new MyGestureDetector()); mDeckListView.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (gestureDetector.onTouchEvent(event)) { return true; } return false; } }); } }