Example usage for android.content Intent setFlags

List of usage examples for android.content Intent setFlags

Introduction

In this page you can find the example usage for android.content Intent setFlags.

Prototype

public @NonNull Intent setFlags(@Flags int flags) 

Source Link

Document

Set special flags controlling how this intent is handled.

Usage

From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java

public void onAppPicked(ResolveInfo info) {
    final Intent intent = new Intent(virtualIntent);
    intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_FORWARD_RESULT);
    intent.setComponent(//  w w w  .  ja  v a2 s .c o m
            new ComponentName(info.activityInfo.applicationInfo.packageName, info.activityInfo.name));
    startActivityForResult(intent, CODE_FORWARD);
}

From source file:com.rainmakerlabs.bleepsample.BleepService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d(TAG, "onStartCommand");
    String actionName = intent.getStringExtra("actionName");
    if (intent == null || intent.getExtras() == null) {//just removing these checks
    } else if (actionName.equalsIgnoreCase(BLEepService.INTENT_BLEEP_PROCESS)
            && intent.getExtras().containsKey(BLEepService.INTENT_BLEEP_PASSED_LIST)) {
        ArrayList<Bleep> bleeps = (ArrayList<Bleep>) intent.getExtras()
                .getSerializable(BLEepService.INTENT_BLEEP_PASSED_LIST);
        for (final Bleep bleep : bleeps) {
            String msgType = bleep.getType();
            String atts = bleep.getAtts();
            try {
                JSONObject objMsg = new JSONObject(atts);
                //thisBleepService.addExtraLog(bleep, "FEEDBACK", "good");//use this when you want to send a custom log to BMS. for instance, you could display a feedback dialog, and ask users to give a rating, and BMS will help you collate the information. put this where necessary, it's just here for example
                Log.d(TAG, "Message Received of Type: " + msgType);
                if (msgType.equalsIgnoreCase("image")) {
                    final String strImgUrl = objMsg.optString(APIKeyDefineCommand.MSG_IMG);
                    final String adAspect = objMsg.optString(APIKeyDefineCommand.MSG_IMGASP);
                    String strImgMsgTemp = objMsg.optString(APIKeyDefineCommand.MSG_NOTIF);
                    //putting the default message above would only work for missing key, not in case of empty string. empty string will prevent the notification, so fix below
                    if (strImgMsgTemp.equalsIgnoreCase(""))
                        strImgMsgTemp = "No Message";
                    final String strImgMsg = strImgMsgTemp;
                    if (checkIfClosed()) {
                        if (oldcodeon)
                            localNotification("", strImgMsg, 0);
                        continue;
                    }/*from  ww  w  .ja  va 2 s. c  o m*/
                    if (MainActivity.adlib.get(strImgMsg) == null && !strImgMsg.equalsIgnoreCase("No Message"))
                        Log.d(TAG, "image url start download for key: " + strImgMsg + ", url = " + strImgUrl);
                    else {
                        Log.d(TAG, "Image exists, or no message, not downloading..., key: " + strImgMsg);
                        continue;
                    }

                    if (strImgMsg.equalsIgnoreCase("$28")) {
                        Log.d("Portal", "Image exists, loading from cache");
                        imgShow(BitmapFactory.decodeResource(getResources(), R.drawable.singtel), strImgMsg);
                        continue;
                    } else if (strImgMsg.equalsIgnoreCase("$4.50")) {
                        Log.d("Portal", "Heineken Image exists, loading from cache");
                        imgShow(BitmapFactory.decodeResource(getResources(), R.drawable.heineken), strImgMsg);
                        continue;
                    }

                    ShutterbugManager.getSharedImageManager(BleepActivity.currentBleepActivity)
                            .download(strImgUrl, new ShutterbugManagerListener() {
                                @Override
                                public void onImageSuccess(ShutterbugManager imageManager, Bitmap bitmap,
                                        String url) {
                                    Log.d(TAG, "image url end download " + strImgUrl);
                                    if (strImgUrl.equalsIgnoreCase(AdDialog.getCurrentAdUrl()))
                                        return;
                                    if (AdDialog.howManyAdDialogsShowing == 1) {
                                        AdDialog.closeOnlyAdDialog();
                                    }
                                    final Bitmap bitmap2 = bitmap;

                                    imgShow(bitmap, strImgMsg);

                                    if (oldcodeon) {
                                        BleepActivity.currentBleepActivity.runOnUiThread(new Runnable() {
                                            public void run() {
                                                if (BleepActivity.isBackground)
                                                    localNotification("", strImgMsg, 0);
                                                AdDialog.showAdsDialog(BleepActivity.currentBleepActivity,
                                                        bitmap2, strImgUrl, adAspect);
                                            }
                                        });
                                    }
                                }

                                @Override
                                public void onImageFailure(ShutterbugManager imageManager, String url) {
                                    thisBleepService.eraseTriggerLog(bleep);//to cancel trigger log when trigger is cancelled
                                }
                            });
                } else if (oldcodeon == false) {//don't run anything else
                } else if (msgType.equalsIgnoreCase("alert") && oldcodeon) {

                    // show alert message
                    if (checkIfClosed() || BleepActivity.isBackground) {
                        localNotification(objMsg.optString(APIKeyDefineCommand.MSG_TITLE),
                                objMsg.optString(APIKeyDefineCommand.MSG_CONTENT), 1);
                    } else {
                        showAlert(objMsg.optString(APIKeyDefineCommand.MSG_TITLE),
                                objMsg.optString(APIKeyDefineCommand.MSG_CONTENT));
                    }
                } else if (msgType.equalsIgnoreCase("launch")) {
                    String intentAction = objMsg.optString(APIKeyDefineCommand.MSG_APP_INTENT);
                    String intentUri = objMsg.optString(APIKeyDefineCommand.MSG_APP_URI);
                    String intentType = "";
                    String intentExtras = objMsg.optString(APIKeyDefineCommand.MSG_APP_EXTRAS);
                    String cfmMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_CFM);
                    String failMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_FAIL);
                    processTypeLaunch(intentAction, intentUri, intentType, intentExtras, cfmMsg, failMsg, 2);
                } else if (msgType.equalsIgnoreCase("url")) {
                    String intentAction = Intent.ACTION_VIEW;
                    String intentUri = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    String intentType = "";
                    String intentExtras = "";
                    String cfmMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_CFM);
                    String failMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_FAIL);
                    processTypeLaunch(intentAction, intentUri, intentType, intentExtras, cfmMsg, failMsg, 3);
                } else if (msgType.equalsIgnoreCase("webview")) {
                    String intentAction = Intent.ACTION_VIEW;
                    String intentUri = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    String intentType = "";
                    String intentExtras = "";
                    String cfmMsg = objMsg.optString(APIKeyDefineCommand.MSG_NOTIF);
                    if (cfmMsg.equalsIgnoreCase(""))
                        cfmMsg = "View webpage?";
                    String failMsg = "";
                    processTypeLaunch(intentAction, intentUri, intentType, intentExtras, cfmMsg, failMsg, 4);
                } else if (msgType.equalsIgnoreCase("video")) {
                    String strVidUrl = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    Intent vidIntent = new Intent(this, VideoActivity.class);
                    vidIntent.putExtra("url", strVidUrl);
                    String notifMsg = objMsg.optString(APIKeyDefineCommand.MSG_NOTIF);
                    if (notifMsg.equalsIgnoreCase(""))
                        notifMsg = "Play video?";
                    if (!checkIfClosed() && BleepActivity.isVideoActivityOpen) {
                        thisBleepService.eraseTriggerLog(bleep);//to cancel trigger log when trigger is cancelled
                    } else if (checkIfClosed() || BleepActivity.isBackground) {
                        vidIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        vidIntent.setAction(Intent.ACTION_MAIN);
                        vidIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                        localNotification("", notifMsg, vidIntent, "Video opening failed!", 5);
                    } else {
                        BleepActivity.currentBleepActivity.startActivity(vidIntent);
                    }
                } else if (msgType.equalsIgnoreCase("audio")) {
                    String url = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    mediaPlayer = new MediaPlayer();
                    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                    try {
                        mediaPlayer.setDataSource(url);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    mediaPlayer.prepareAsync();
                    mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                        @Override
                        public void onPrepared(MediaPlayer mp) {
                            mp.start();
                        }
                    });
                    mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                        @Override
                        public boolean onError(MediaPlayer mp, int what, int extra) {
                            return false;
                        }
                    });
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        //      } else if (actionName.equalsIgnoreCase(BLEepService.INTENT_BLEEP_EXIT) && intent.getExtras().containsKey(BLEepService.INTENT_MSG_NAME)) {
        //         HashMap<String, Object> beaconOutInfo = (HashMap<String, Object>)intent.getSerializableExtra(BLEepService.INTENT_MSG_NAME);   
        //         //Log.d("debug!","debug! this beacon just went out "+beaconOutInfo.get("uuid")+" "+beaconOutInfo.get("major")+" "+beaconOutInfo.get("minor")+" "+beaconOutInfo.get("tag")+" "+beaconOutInfo.get("beaconID"));
    } else if (actionName.equalsIgnoreCase(BLEepService.INTENT_BLEEP_STATE)
            && intent.getExtras().containsKey(BLEepService.INTENT_MSG_NAME)) {
        int beaconState = intent.getIntExtra(BLEepService.INTENT_MSG_NAME, 99);
    }

    return START_NOT_STICKY;
}

From source file:com.google.appinventor.components.runtime.ProbeBase.java

@SimpleFunction(description = "Create a notication with message to wake up "
        + "another activity when tap on the notification")
public void CreateNotification(String title, String text, boolean enabledSound, boolean enabledVibrate,
        String packageName, String className, String extraKey, String extraVal) throws ClassNotFoundException {

    Intent activityToLaunch = new Intent(Intent.ACTION_MAIN);

    Log.i(TAG, "packageName: " + packageName);
    Log.i(TAG, "className: " + className);

    // for local AI instance, all classes are under the package
    // "appinventor.ai_test"
    // but for those runs on Google AppSpot(AppEngine), the package name will be
    // "appinventor.ai_GoogleAccountUserName"
    // e.g. pakageName = appinventor.ai_HomerSimpson.HelloPurr
    // && className = appinventor.ai_HomerSimpson.HelloPurr.Screen1

    ComponentName component = new ComponentName(packageName, className);
    activityToLaunch.setComponent(component);
    activityToLaunch.putExtra(extraKey, extraVal);

    Log.i(TAG, "we found the class for intent to send into notificaiton");

    activityToLaunch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    mContentIntent = PendingIntent.getActivity(mainUIThreadActivity, 0, activityToLaunch, 0);

    Long currentTimeMillis = System.currentTimeMillis();
    notification = new Notification(R.drawable.stat_notify_chat, "Activate Notification!", currentTimeMillis);

    Log.i(TAG, "After creating notification");
    notification.contentIntent = mContentIntent;
    notification.flags = Notification.FLAG_AUTO_CANCEL;

    // reset the notification
    notification.defaults = 0;/*from   w w  w . ja v a2  s  . co m*/

    if (enabledSound)
        notification.defaults |= Notification.DEFAULT_SOUND;

    if (enabledVibrate)
        notification.defaults |= Notification.DEFAULT_VIBRATE;

    notification.setLatestEventInfo(mainUIThreadActivity, (CharSequence) title, (CharSequence) text,
            mContentIntent);
    Log.i(TAG, "after updated notification contents");
    mNM.notify(PROBE_NOTIFICATION_ID, notification);
    Log.i(TAG, "notified");

}

From source file:org.sirimangalo.meditationplus.ActivityMain.java

private void showLogin() {
    doingLogin = true;/*from   w w  w. j a  v  a 2s .co m*/
    Intent i = new Intent(this, ActivityLogin.class);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivityForResult(i, LOGIN_CODE);
}

From source file:com.qiscus.sdk.ui.fragment.QiscusBaseChatFragment.java

@Override
public void onFileDownloaded(File file, String mimeType) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        intent.setDataAndType(Uri.fromFile(file), mimeType);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    } else {//from   w ww .  j  a  va 2 s. c  o m
        intent.setDataAndType(FileProvider.getUriForFile(getActivity(), Qiscus.getProviderAuthorities(), file),
                mimeType);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        showError(getString(R.string.chat_error_no_handler));
    }
}

From source file:com.egloos.hyunyi.musicinfo.LinkPopUp.java

@Override
public void onCreate(Bundle saveInstanceState) {
    super.onCreate(saveInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    Bundle b = getIntent().getExtras();/*  w ww  .j a v a2  s .  co m*/

    SharedPreferences prefs = getSharedPreferences("settings", MODE_PRIVATE);

    imageOptions = new DisplayImageOptions.Builder().cacheInMemory(false).cacheOnDisk(true)
            .bitmapConfig(Bitmap.Config.RGB_565).imageScaleType(ImageScaleType.EXACTLY)
            .showImageOnLoading(R.drawable.connecting_anim).build();
    config = new ImageLoaderConfiguration.Builder(getApplicationContext()).diskCacheExtraOptions(480, 320, null)
            .defaultDisplayImageOptions(imageOptions).build();

    if (imageLoader == null)
        imageLoader = ImageLoader.getInstance();
    if (!imageLoader.isInited())
        imageLoader.init(config);

    setContentView(R.layout.link_dialog);

    imageFrame = (FrameLayout) findViewById(R.id.image_frame);
    iBottomPanel = (ImageView) findViewById(R.id.bottom_panel);

    lArtistLink = (RelativeLayout) findViewById(R.id.l_artist_link);

    bPopUpClose = (ImageView) findViewById(R.id.b_popup_close);
    bPopUpClose.setOnClickListener(this);

    tEchoNest = (TextView) findViewById(R.id.t_echo_nest);
    tAttribution = (TextView) findViewById(R.id.t_attribution);

    tArtistName = (TextView) findViewById(R.id.t_artist_name);
    tArtistName.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                //isMove = false;
                mTouchX = event.getRawX();
                mTouchY = event.getRawY();
                break;

            case MotionEvent.ACTION_UP:
                //Log.i("musicInfo", "ACTION_UP! TouchY:" + mTouchY + " UpY: " + event.getRawY() + " Move: " + (mTouchY - event.getRawY()));
                int RawY = (int) event.getRawY();
                int dY = (int) (mTouchY - event.getRawY());
                if (dY > 200) {
                    imageLoader.resume();
                    //Log.i("musicInfo", "mGridView TOP = " + mGridView.getTop() + " mGridView TransitionY =" + mGridView.getTranslationY());
                    while (mGridView.getTranslationY() > tArtistName.getHeight()) {
                        //Log.i("musicInfo", "Moving UP! mGridView: " + mGridView.getTranslationY() + " tArtistName: " + tArtistName.getTranslationY());
                        mGridView.setTranslationY(mGridView.getTranslationY() - 1);
                        tArtistName.setTranslationY(tArtistName.getTranslationY() - 1);

                    }
                } else if (dY > 5 && dY <= 200 || (dY <= 5 && tArtistName.getTranslationY() < 0)) {
                    while (tArtistName.getTranslationY() < 0) {
                        //Log.i("musicInfo", "Moving DOWN! mGridView: " + mGridView.getTranslationY() + " tArtistName: " + tArtistName.getTranslationY());
                        mGridView.setTranslationY(mGridView.getTranslationY() + 1);
                        tArtistName.setTranslationY(tArtistName.getTranslationY() + 1);
                    }
                    imageLoader.pause();
                }
                break;

            case MotionEvent.ACTION_MOVE:
                //isMove = true;

                //int top = tArtistName.getTop();
                //int bottom = tArtistName.getBottom();
                //int left = tArtistName.getLeft();
                //int right = tArtistName.getRight();

                int x = (int) (event.getRawX() - mTouchX);
                int y = (int) (event.getRawY() - mTouchY);

                final int num = 5;
                if (y > -num && y < num) {
                    //isMove = false;
                    break;
                } else if (y > 0) {

                } else {
                    imageFrame.bringChildToFront(mGridView);
                    tArtistName.setTranslationY((float) y);
                    mGridView.setTranslationY((float) (SGVtransition + y));

                    //Log.i("musicInfo", String.format("T: %d, B: %d", mGridView.getTop(), mGridView.getBottom()));

                }

                break;
            }
            return true;
        }
    });

    ArtistImage = (ImageView) findViewById(R.id.artist_image);

    lLinkList = (LinearLayout) findViewById(R.id.l_link_list);

    mGridView = (StaggeredGridView) findViewById(R.id.SG_view);

    SGVtransition = 900;

    mGridView.setTranslationY(SGVtransition);

    JSONObject artist_info = null;
    try {
        artist_info = new JSONObject(b.getString("artist_info"));
        Log.i("musicInfo", "LinkPopUp. OnCreate" + artist_info.toString());
        displayArtistInfo(artist_info);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    if (artist_info != null)
        jArtists.put(artist_info);
    if (prefs.getBoolean("SimilarOn", false)) {
        getSimilarArtistsInfo((String) tArtistName.getText());
        ArtistImage.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    //isMove = false;
                    mTouchX = event.getRawX();
                    mTouchY = event.getRawY();
                    break;

                case MotionEvent.ACTION_UP:
                    //Log.i("musicInfo", "ACTION_UP! TouchY:" + mTouchY + " UpY: " + event.getRawY() + " Move: " + (mTouchY - event.getRawY()));
                    int dX = (int) (mTouchX - event.getRawX());
                    if (dX > 5) {
                        if (jArtists.length() > 1) {
                            imageLoader.stop();
                            try {
                                if (artistNum == 0) {
                                    artistNum = jArtists.length() - 1;
                                } else {
                                    artistNum--;
                                }

                                displayArtistInfo(jArtists.getJSONObject(artistNum));
                                imageLoader.resume();

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        }

                    } else if (dX < -5) {
                        if (jArtists.length() > 1) {
                            imageLoader.stop();
                            try {
                                if (artistNum == jArtists.length() - 1) {
                                    artistNum = 0;
                                } else {
                                    artistNum++;
                                }
                                displayArtistInfo(jArtists.getJSONObject(artistNum));
                                imageLoader.resume();
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        }

                    }

                    break;

                case MotionEvent.ACTION_MOVE:

                    break;
                }

                return true;
            }
        });
    }

    mGridView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            //Log.d("musicInfo", "SGV onScrollStateChanged:" + scrollState);
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            //Log.d("musicInfo", "SGV onScroll firstVisibleItem:" + firstVisibleItem + " visibleItemCount:" + visibleItemCount + " totalItemCount:" + totalItemCount);
            // our handling
            if (!mHasRequestedMore) {
                int lastInScreen = firstVisibleItem + visibleItemCount;
                if (lastInScreen >= totalItemCount) {
                    //Log.d("musicInfo", "SGV onScroll lastInScreen - so load more");
                    mHasRequestedMore = true;
                    onLoadMoreItems();
                }
            }
        }

        private void onLoadMoreItems() {
            if (jVideoArray == null)
                return;
            final ArrayList<JSONObject> sampleData = generateImageData(jVideoArray);
            for (JSONObject data : sampleData) {
                mAdapter.add(data);
            }
            // stash all the data in our backing store
            mData.addAll(sampleData);
            // notify the adapter that we can update now
            mAdapter.notifyDataSetChanged();
            mHasRequestedMore = false;
        }
    });

    mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(getApplicationContext(), "Open the Video...", Toast.LENGTH_SHORT).show();
            StaggeredViewAdapter.ViewHolder vh = (StaggeredViewAdapter.ViewHolder) view.getTag();

            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setData(Uri.parse((String) vh.url));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            //finish();

        }

    });

    //int[] lArtistLinkPosition = new int[2];
    //int[] tArtistNamePosition = new int[2];

    //lArtistLink.getLocationOnScreen(lArtistLinkPosition);
    //tArtistName.getLocationOnScreen(tArtistNamePosition);

    //Log.d("musicInfo", "SGV transition = " + SGVtransition);
}

From source file:com.owncloud.android.ui.fragment.FileDetailFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.fdDownloadBtn: {
        FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
        FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
        if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) {
            downloaderBinder.cancel(mAccount, mFile);
            if (mFile.isDown()) {
                setButtonsForDown();//from   www  .ja va2s .co  m
            } else {
                setButtonsForRemote();
            }

        } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile)) {
            uploaderBinder.cancel(mAccount, mFile);
            if (!mFile.fileExists()) {
                // TODO make something better
                if (getActivity() instanceof FileDisplayActivity) {
                    // double pane
                    FragmentTransaction transaction = getActivity().getSupportFragmentManager()
                            .beginTransaction();
                    transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FTAG); // empty FileDetailFragment
                    transaction.commit();
                    mContainerActivity.onFileStateChanged();
                } else {
                    getActivity().finish();
                }

            } else if (mFile.isDown()) {
                setButtonsForDown();
            } else {
                setButtonsForRemote();
            }

        } else {
            mLastRemoteOperation = new SynchronizeFileOperation(mFile, null, mStorageManager, mAccount, true,
                    false, getActivity());
            WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount,
                    getSherlockActivity().getApplicationContext());
            mLastRemoteOperation.execute(wc, this, mHandler);

            // update ui 
            boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
            getActivity().showDialog((inDisplayActivity) ? FileDisplayActivity.DIALOG_SHORT_WAIT
                    : FileDetailActivity.DIALOG_SHORT_WAIT);
            setButtonsForTransferring(); // disable button immediately, although the synchronization does not result in a file transference

        }
        break;
    }
    case R.id.fdKeepInSync: {
        CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync);
        mFile.setKeepInSync(cb.isChecked());
        mStorageManager.saveFile(mFile);

        /// register the OCFile instance in the observer service to monitor local updates;
        /// if necessary, the file is download 
        Intent intent = new Intent(getActivity().getApplicationContext(), FileObserverService.class);
        intent.putExtra(FileObserverService.KEY_FILE_CMD,
                (cb.isChecked() ? FileObserverService.CMD_ADD_OBSERVED_FILE
                        : FileObserverService.CMD_DEL_OBSERVED_FILE));
        intent.putExtra(FileObserverService.KEY_CMD_ARG_FILE, mFile);
        intent.putExtra(FileObserverService.KEY_CMD_ARG_ACCOUNT, mAccount);
        Log.e(TAG, "starting observer service");
        getActivity().startService(intent);

        if (mFile.keepInSync()) {
            onClick(getView().findViewById(R.id.fdDownloadBtn)); // force an immediate synchronization
        }
        break;
    }
    case R.id.fdRenameBtn: {
        EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title),
                mFile.getFileName(), this);
        dialog.show(getFragmentManager(), "nameeditdialog");
        break;
    }
    case R.id.fdRemoveBtn: {
        ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
                R.string.confirmation_remove_alert, new String[] { mFile.getFileName() },
                mFile.isDown() ? R.string.confirmation_remove_remote_and_local
                        : R.string.confirmation_remove_remote,
                mFile.isDown() ? R.string.confirmation_remove_local : -1, R.string.common_cancel);
        confDialog.setOnConfirmationListener(this);
        mCurrentDialog = confDialog;
        mCurrentDialog.show(getFragmentManager(), FTAG_CONFIRMATION);
        break;
    }
    case R.id.fdOpenBtn: {
        String storagePath = mFile.getStoragePath();
        String encodedStoragePath = WebdavUtils.encodePath(storagePath);
        try {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setDataAndType(Uri.parse("file://" + encodedStoragePath), mFile.getMimetype());
            i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            startActivity(i);

        } catch (Throwable t) {
            Log.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: "
                    + mFile.getMimetype());
            boolean toastIt = true;
            String mimeType = "";
            try {
                Intent i = new Intent(Intent.ACTION_VIEW);
                mimeType = MimeTypeMap.getSingleton()
                        .getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
                if (mimeType == null || !mimeType.equals(mFile.getMimetype())) {
                    if (mimeType != null) {
                        i.setDataAndType(Uri.parse("file://" + encodedStoragePath), mimeType);
                    } else {
                        // desperate try
                        i.setDataAndType(Uri.parse("file://" + encodedStoragePath), "*/*");
                    }
                    i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                    startActivity(i);
                    toastIt = false;
                }

            } catch (IndexOutOfBoundsException e) {
                Log.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath);

            } catch (ActivityNotFoundException e) {
                Log.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType
                        + " obtained from extension");

            } catch (Throwable th) {
                Log.e(TAG, "Unexpected problem when opening: " + storagePath, th);

            } finally {
                if (toastIt) {
                    Toast.makeText(getActivity(),
                            "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT)
                            .show();
                }
            }

        }
        break;
    }
    default:
        Log.e(TAG, "Incorrect view clicked!");
    }

    /* else if (v.getId() == R.id.fdShareBtn) {
    Thread t = new Thread(new ShareRunnable(mFile.getRemotePath()));
    t.start();
    }*/
}

From source file:com.egloos.hyunyi.musicinfo.LinkPopUp.java

private void displayArtistInfo_bk(JSONObject j) throws JSONException {
    if (imageLoader == null)
        imageLoader = ImageLoader.getInstance();
    if (!imageLoader.isInited())
        imageLoader.init(config);/*from w w w . ja va  2 s .  c  o  m*/

    Log.i("musicInfo", "LinkPopUp. displayArtistInfo " + j.toString());

    JSONObject j_artist_info = j.getJSONObject("artist");

    tArtistName.setText(j_artist_info.getString("name"));
    final JSONObject urls = j_artist_info.optJSONObject("urls");
    final JSONArray videos = j_artist_info.optJSONArray("video");
    final JSONArray images = j_artist_info.optJSONArray("images");
    final String fm_image = j.optString("fm_image");
    final JSONArray available_images = new JSONArray();
    ArrayList<String> image_urls = new ArrayList<String>();

    if (fm_image != null) {
        image_urls.add(fm_image);
    }

    Log.i("musicInfo", images.toString());

    if (images != null) {
        for (int i = 0; i < images.length(); i++) {
            JSONObject image = images.getJSONObject(i);
            int width = image.optInt("width", 0);
            int height = image.optInt("height", 0);
            String url = image.optString("url", "");
            Log.i("musicInfo", i + ": " + url);
            if ((width * height > 10000) && (width * height < 100000) && (!url.contains("userserve-ak"))) {
                //if ((width>300&&width<100)&&(height>300&&height<1000)&&(!url.contains("userserve-ak"))) {
                image_urls.add(url);
                Log.i("musicInfo", "Selected: " + url);
                //available_images.put(image);
            }
        }

        int random = (int) (Math.random() * image_urls.size());
        final String f_url = image_urls.get(random);

        //int random = (int) (Math.random() * available_images.length());
        //final JSONObject fImage = available_images.length()>0?available_images.getJSONObject(random > images.length() ? 0 : random):images.getJSONObject(0);

        Log.i("musicInfo",
                "Total image#=" + available_images.length() + " Selected image#=" + random + " " + f_url);

        imageLoader.displayImage(f_url, ArtistImage, new ImageLoadingListener() {
            @Override
            public void onLoadingStarted(String imageUri, View view) {

            }

            @Override
            public void onLoadingFailed(String imageUri, View view, FailReason failReason) {

            }

            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {

                lLinkList.removeAllViews();
                //String attr = fImage.optJSONObject("license").optString("attribution");
                //tAttribution.setText("Credit. " + ((attr == null) || (attr.contains("n/a")) ? "Unknown" : attr));
                if (urls != null) {
                    String[] jsonName = { "wikipedia_url", "mb_url", "lastfm_url", "official_url",
                            "twitter_url" };
                    for (int i = 0; i < jsonName.length; i++) {
                        if ((urls.optString(jsonName[i]) != null) && (urls.optString(jsonName[i]) != "")) {
                            Log.d("musicinfo", "Link URL: " + urls.optString(jsonName[i]));
                            TextView tv = new TextView(getApplicationContext());
                            tv.setTextSize(11);
                            tv.setPadding(16, 16, 16, 16);
                            tv.setTextColor(Color.LTGRAY);
                            tv.setTypeface(Typeface.SANS_SERIF);
                            tv.setGravity(Gravity.CENTER_VERTICAL);
                            tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                                    ViewGroup.LayoutParams.WRAP_CONTENT));

                            switch (jsonName[i]) {
                            case "official_url":
                                tv.setText("HOME.");
                                break;
                            case "wikipedia_url":
                                tv.setText("WIKI.");
                                break;
                            case "mb_url":
                                tv.setText("Music Brainz.");
                                break;
                            case "lastfm_url":
                                tv.setText("Last FM.");
                                break;
                            case "twitter_url":
                                tv.setText("Twitter.");
                                break;
                            }

                            try {
                                tv.setTag(urls.getString(jsonName[i]));
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                            tv.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    Intent intent = new Intent();
                                    intent.setAction(Intent.ACTION_VIEW);
                                    intent.addCategory(Intent.CATEGORY_BROWSABLE);
                                    intent.setData(Uri.parse((String) v.getTag()));
                                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                    startActivity(intent);
                                    Toast.makeText(getApplicationContext(), "Open the Link...",
                                            Toast.LENGTH_SHORT).show();
                                    //finish();
                                }
                            });
                            lLinkList.addView(tv);
                        }
                    }
                } else {
                    TextView tv = new TextView(getApplicationContext());
                    tv.setTextSize(11);
                    tv.setPadding(16, 16, 16, 16);
                    tv.setTextColor(Color.LTGRAY);
                    tv.setTypeface(Typeface.SANS_SERIF);
                    tv.setGravity(Gravity.CENTER_VERTICAL);
                    tv.setText("Sorry, No Link Here...");
                    lLinkList.addView(tv);
                }

                if (videos != null) {
                    jVideoArray = videos;
                    mAdapter = new StaggeredViewAdapter(getApplicationContext(),
                            android.R.layout.simple_list_item_1, generateImageData(videos));
                    //if (mData == null) {
                    mData = generateImageData(videos);
                    //}

                    //mAdapter.clear();

                    for (JSONObject data : mData) {
                        mAdapter.add(data);
                    }
                    mGridView.setAdapter(mAdapter);
                } else {

                }

                adjBottomColor(((ImageView) view).getDrawable());
            }

            @Override
            public void onLoadingCancelled(String imageUri, View view) {

            }
        });
    }

}

From source file:com.safecell.HomeScreenActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    // android:background="@drawable/stop_button"

    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    Log.v(TAG, "on create");
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setWindowAnimations(R.anim.null_animation);

    contextHomeScreenActivity = HomeScreenActivity.this;

    mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    profilesRepository = new ProfilesRepository(contextHomeScreenActivity);
    isgameplay = this.GamplayOnOff();
    if (!InformatonUtils.isServiceRunning(this)) {
        startService();//from  ww w. ja v  a2  s.c om
    }
    // ServiceHandler.getInstance(this).bindService();

    this.initUI();
    Log.v(TAG, "Emergencies.Inbound_Details Size:" + Emergencies.Inbound_Details.size());

    // Request for Emergency numbers
    new EmergencyHandler(contextHomeScreenActivity, profilesRepository.getId()).execute();

    IsTripPaused();
    IsTripSaved();

    Log.d(TAG, "Setings = "
            + getSharedPreferences("SETTINGS", MODE_WORLD_READABLE).getBoolean("isDisabled", false));

    sharedPreferences = getSharedPreferences("TRIP", MODE_WORLD_READABLE);

    this.recentTripLog();

    deleteFile(WayPointStore.WAY_POINT_FILE);
    deleteFile(InterruptionStore.INTERRUPTION_POINT_FILE);

    // setListAdapter(new recentTripAdapater(HomeScreenActivity.this));

    if (isAppTermited())

    {
        deleteLastTempTrip();
        Intent mIntent = new Intent(HomeScreenActivity.this, TrackingScreenActivity.class);
        mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        Log.v("HomeScreenActivity", "AppTerminated");
        startActivity(mIntent);

        finish();
        // clearTrackingScreenPref();
    }

    /*
     * if(!isAppTermited()) { Log.v("SafeCell: Temp data",
     * "Delete Last Data"); deleteLastTempTrip(); }
     */

}

From source file:kr.co.bettersoft.checkmileage.activities.GCMIntentService.java

/**
 * generateNotification//  w  w  w .  jav a2s  .  c  o  m
 * Issues a notification to inform the user that server has sent a message.
 * @param context
 * @param message
 * @return
 */
private void generateNotification(Context context, String message) {
    int icon = R.drawable.ic_stat_gcm;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when); // sdf
    String title = context.getString(R.string.app_name);
    String mileageUpdateStr = context.getString(R.string.mileage_noti);
    Intent notificationIntent;
    /*
     * MILEAGE :  ? ??  ? ???.
     * MARKETING : ?? ?    ?.
     * Check Mileage     ?. : test ..
     * 
     * <string name="gcm_new_msgkkk"> </string>
     */
    String new_msg = " ";

    if (message.equals(new_msg)) {
        Log.d(TAG, "new msg - test");
        notificationIntent = new Intent(context, DummyActivity.class);
        //            notificationIntent.putExtra("RunMode", "TEST");                  // ?? ? . ?? .. ?   ..
        notificationIntent.putExtra("RunMode", "MILEAGE"); //

        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
        //                    | Intent.FLAG_ACTIVITY_CLEAR_TOP 
        //                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);

        //        }else if(message.contains("MILEAGE")){
        //        }else if(message.contains(mileageUpdateStr)){         // ?? ?. ()
    } else if (message.equals(mileageUpdateStr)) { // ?? ?. ().
        Log.d(TAG, "update mileage");
        MyMileagePageActivity.searched = false;
        //           notificationIntent = new Intent(context, MainActivity.class);      // ? ?  ?..
        notificationIntent = new Intent(context, DummyActivity.class);
        notificationIntent.putExtra("RunMode", "MILEAGE");

        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
        //                    | Intent.FLAG_ACTIVITY_CLEAR_TOP 
        //                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);
    } else if (message.equals("MARKETING")) {
        Log.d(TAG, "noti event push");
        //           notificationIntent = new Intent(context, MainActivity.class);      // ? ?  ? ?  ..
        notificationIntent = new Intent(context, DummyActivity.class);
        notificationIntent.putExtra("RunMode", "MARKETING");
        notificationIntent.putExtra("MESSAGE", "New Event");
        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
        //                    | Intent.FLAG_ACTIVITY_CLEAR_TOP 
        //                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);
    } else { //  ?.
        Log.d(TAG, "noti event push");
        //           notificationIntent = new Intent(context, MainActivity.class);      // ? ?  ? ?  ..
        notificationIntent = new Intent(context, DummyActivity.class);
        notificationIntent.putExtra("RunMode", "MARKETING");
        notificationIntent.putExtra("MESSAGE", message);

        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
        //                    | Intent.FLAG_ACTIVITY_CLEAR_TOP 
        //                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);
    }
}