Example usage for android.content Intent getType

List of usage examples for android.content Intent getType

Introduction

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

Prototype

public @Nullable String getType() 

Source Link

Document

Retrieve any explicit MIME type included in the intent.

Usage

From source file:be.brunoparmentier.wifikeyshare.ui.activities.WifiNetworkActivity.java

private void handleIntent(Intent intent) {
    Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    String action = intent.getAction();
    Log.d(TAG, "handleIntent: action=" + action);
    if (isInWriteMode) {
        /* Write tag */
        Log.d(TAG, "Writing tag");
        if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)
                || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {

            if (NfcUtils.writeTag(wifiNetwork, tag)) {
                Toast.makeText(this, R.string.nfc_tag_written, Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(this, R.string.error_nfc_tag_write, Toast.LENGTH_LONG).show();
            }//  w ww . j a  va  2 s.  c o m
            disableTagWriteMode();
        }
    } else {
        /* Read tag */
        Log.d(TAG, "Reading tag");

        if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
            if (NfcUtils.NFC_TOKEN_MIME_TYPE.equals(intent.getType())) {
                Intent configureNetworkIntent = new Intent(intent)
                        .setClass(this, ConfirmConnectToWifiNetworkActivity.class)
                        .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(configureNetworkIntent);
            } else {
                Log.d(TAG, "Not a Wi-Fi configuration tag");
            }
        }
    }
}

From source file:dentex.youtube.downloader.ShareActivity.java

@SuppressLint("CutPasteId")
@Override/*from   www. j  a  va  2 s. c  om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = getBaseContext();
    settings = getSharedPreferences(PREFS_NAME, 0);

    // Theme init
    Utils.themeInit(this);

    setContentView(R.layout.activity_share);

    showSizesInVideoList = settings.getBoolean("show_size_list", false);

    // Language init
    Utils.langInit(this);

    // loading views from the layout xml
    tv = (TextView) findViewById(R.id.textView1);

    progressBarD = (ProgressBar) findViewById(R.id.progressBarD);
    progressBarL = (ProgressBar) findViewById(R.id.progressBarL);

    String theme = settings.getString("choose_theme", "D");
    if (theme.equals("D")) {
        progressBar1 = progressBarD;
        progressBarL.setVisibility(View.GONE);
    } else {
        progressBar1 = progressBarL;
        progressBarD.setVisibility(View.GONE);
    }

    imgView = (ImageView) findViewById(R.id.imgview);

    lv = (ListView) findViewById(R.id.list);

    // YTD update initialization
    updateInit();

    // Get intent, action and MIME type
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            try {
                handleSendText(intent, action);
                Utils.logger("d", "handling ACTION_SEND", DEBUG_TAG);
            } catch (IOException e) {
                e.printStackTrace();
                Log.e(DEBUG_TAG, "Error: " + e.toString(), e);
            }
        }
    }

    if (Intent.ACTION_VIEW.equals(action)) {
        try {
            handleSendText(intent, action);
            Utils.logger("d", "handling ACTION_VIEW", DEBUG_TAG);
        } catch (IOException e) {
            e.printStackTrace();
            Log.e(DEBUG_TAG, "Error: " + e.toString(), e);
        }
    }
}

From source file:com.becapps.easydownloader.ShareActivity.java

@SuppressLint("CutPasteId")
@Override/* w  ww. j  av a2  s . co  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Appirater.appLaunched(this);
    AppBrain.initApp(this);
    startAppAd.showAd(); // show the ad
    startAppAd.loadAd(); // load the next ad

    mContext = getBaseContext();
    settings = getSharedPreferences(PREFS_NAME, 0);

    // Theme init
    Utils.themeInit(this);

    setContentView(R.layout.activity_share);

    showSizesInVideoList = settings.getBoolean("show_size_list", false);

    // Language init
    Utils.langInit(this);

    // loading views from the layout xml
    tv = (TextView) findViewById(R.id.textView1);

    progressBarD = (ProgressBar) findViewById(R.id.progressBarD);
    progressBarL = (ProgressBar) findViewById(R.id.progressBarL);

    String theme = settings.getString("choose_theme", "D");
    if (theme.equals("D")) {
        progressBar1 = progressBarD;
        progressBarL.setVisibility(View.GONE);
    } else {
        progressBar1 = progressBarL;
        progressBarD.setVisibility(View.GONE);
    }

    imgView = (ImageView) findViewById(R.id.imgview);

    lv = (ListView) findViewById(R.id.list);

    // YTD update initialization
    updateInit();

    // Get intent, action and MIME type
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            try {
                handleSendText(intent, action);
                Utils.logger("d", "handling ACTION_SEND", DEBUG_TAG);
            } catch (IOException e) {
                e.printStackTrace();
                Log.e(DEBUG_TAG, "Error: " + e.getMessage(), e);
            }
        }
    }

    AdView adview = (AdView) findViewById(R.id.adView);
    AdRequest re = new AdRequest();
    re.setTesting(true);
    adview.loadAd(re);

    if (Intent.ACTION_VIEW.equals(action)) {
        try {
            handleSendText(intent, action);
            Utils.logger("d", "handling ACTION_VIEW", DEBUG_TAG);
        } catch (IOException e) {
            e.printStackTrace();
            Log.e(DEBUG_TAG, "Error: " + e.getMessage(), e);
        }
    }
}

From source file:com.iiordanov.bVNC.RemoteCanvasActivity.java

void initialize() {
    if (android.os.Build.VERSION.SDK_INT >= 9) {
        android.os.StrictMode.ThreadPolicy policy = new android.os.StrictMode.ThreadPolicy.Builder().permitAll()
                .build();// w  w w  . jav a2s .  c  o m
        android.os.StrictMode.setThreadPolicy(policy);
    }

    handler = new Handler();

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    database = new Database(this);

    Intent i = getIntent();
    connection = null;

    Uri data = i.getData();

    boolean isSupportedScheme = false;
    if (data != null) {
        String s = data.getScheme();
        isSupportedScheme = s.equals("rdp") || s.equals("spice") || s.equals("vnc");
    }

    if (isSupportedScheme || !Utils.isNullOrEmptry(i.getType())) {
        if (isMasterPasswordEnabled()) {
            Utils.showFatalErrorMessage(this,
                    getResources().getString(R.string.master_password_error_intents_not_supported));
            return;
        }

        connection = ConnectionBean.createLoadFromUri(data, this);

        String host = data.getHost();
        if (!host.startsWith(Constants.CONNECTION)) {
            connection.parseFromUri(data);
        }

        if (connection.isSaved()) {
            connection.saveAndWriteRecent(false);
        }
        // we need to save the connection to display the loading screen, so otherwise we should exit
        if (!connection.isReadyForConnection()) {
            if (!connection.isSaved()) {
                Log.i(TAG, "Exiting - Insufficent information to connect and connection was not saved.");
                Toast.makeText(this, getString(R.string.error_uri_noinfo_nosave), Toast.LENGTH_LONG).show();
                ;
            } else {
                // launch bVNC activity
                Log.i(TAG, "Insufficent information to connect, showing connection dialog.");
                Intent bVncIntent = new Intent(this, bVNC.class);
                startActivity(bVncIntent);
            }
            finish();
            return;
        }
    } else {
        connection = new ConnectionBean(this);
        Bundle extras = i.getExtras();

        if (extras != null) {
            connection.Gen_populate((ContentValues) extras.getParcelable(Constants.CONNECTION));
        }

        // Parse a HOST:PORT entry
        String host = connection.getAddress();
        if (host.indexOf(':') > -1) {
            String p = host.substring(host.indexOf(':') + 1);
            try {
                connection.setPort(Integer.parseInt(p));
            } catch (Exception e) {
            }
            connection.setAddress(host.substring(0, host.indexOf(':')));
        }

        if (connection.getPort() == 0)
            connection.setPort(Constants.DEFAULT_VNC_PORT);

        if (connection.getSshPort() == 0)
            connection.setSshPort(Constants.DEFAULT_SSH_PORT);
    }
}

From source file:de.azapps.mirakel.main_activity.MainActivity.java

private void addFilesForTask(final Task t, final Intent intent) {
    final String action = intent.getAction();
    final String type = intent.getType();
    this.currentPosition = getTaskFragmentPosition();
    if (Intent.ACTION_SEND.equals(action) && (type != null)) {
        final Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
        t.addFile(this, uri);
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && (type != null)) {
        final List<Uri> imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        for (final Uri uri : imageUris) {
            t.addFile(this, uri);
        }/*from   ww w  .java  2 s . c o m*/
    }
}

From source file:org.telegram.ui.LaunchActivity.java

private void handleIntent(Intent intent, boolean isNew, boolean restore) {
    boolean pushOpened = false;

    Integer push_user_id = 0;//from w  w w. j  ava 2 s  . co m
    Integer push_chat_id = 0;
    Integer push_enc_id = 0;
    Integer open_settings = 0;

    photoPath = null;
    videoPath = null;
    sendingText = null;
    documentPath = null;
    imagesPathArray = null;
    documentsPathArray = null;

    if (intent != null && intent.getAction() != null && !restore) {
        if (Intent.ACTION_SEND.equals(intent.getAction())) {
            boolean error = false;
            String type = intent.getType();
            if (type != null && type.equals("text/plain")) {
                String text = intent.getStringExtra(Intent.EXTRA_TEXT);
                String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);

                if (text != null && text.length() != 0) {
                    if ((text.startsWith("http://") || text.startsWith("https://")) && subject != null
                            && subject.length() != 0) {
                        text = subject + "\n" + text;
                    }
                    sendingText = text;
                } else {
                    error = true;
                }
            } else if (type != null && type.equals(ContactsContract.Contacts.CONTENT_VCARD_TYPE)) {
                try {
                    Uri uri = (Uri) intent.getExtras().get(Intent.EXTRA_STREAM);
                    if (uri != null) {
                        ContentResolver cr = getContentResolver();
                        InputStream stream = cr.openInputStream(uri);

                        String name = null;
                        String nameEncoding = null;
                        String nameCharset = null;
                        ArrayList<String> phones = new ArrayList<String>();
                        BufferedReader bufferedReader = new BufferedReader(
                                new InputStreamReader(stream, "UTF-8"));
                        String line = null;
                        while ((line = bufferedReader.readLine()) != null) {
                            String[] args = line.split(":");
                            if (args.length != 2) {
                                continue;
                            }
                            if (args[0].startsWith("FN")) {
                                String[] params = args[0].split(";");
                                for (String param : params) {
                                    String[] args2 = param.split("=");
                                    if (args2.length != 2) {
                                        continue;
                                    }
                                    if (args2[0].equals("CHARSET")) {
                                        nameCharset = args2[1];
                                    } else if (args2[0].equals("ENCODING")) {
                                        nameEncoding = args2[1];
                                    }
                                }
                                name = args[1];
                                if (nameEncoding != null && nameEncoding.equalsIgnoreCase("QUOTED-PRINTABLE")) {
                                    while (name.endsWith("=") && nameEncoding != null) {
                                        name = name.substring(0, name.length() - 1);
                                        line = bufferedReader.readLine();
                                        if (line == null) {
                                            break;
                                        }
                                        name += line;
                                    }
                                    byte[] bytes = Utilities.decodeQuotedPrintable(name.getBytes());
                                    if (bytes != null && bytes.length != 0) {
                                        String decodedName = new String(bytes, nameCharset);
                                        if (decodedName != null) {
                                            name = decodedName;
                                        }
                                    }
                                }
                            } else if (args[0].startsWith("TEL")) {
                                String phone = PhoneFormat.stripExceptNumbers(args[1], true);
                                if (phone.length() > 0) {
                                    phones.add(phone);
                                }
                            }
                        }
                        if (name != null && !phones.isEmpty()) {
                            contactsToSend = new ArrayList<TLRPC.User>();
                            for (String phone : phones) {
                                TLRPC.User user = new TLRPC.TL_userContact();
                                user.phone = phone;
                                user.first_name = name;
                                user.last_name = "";
                                user.id = 0;
                                contactsToSend.add(user);
                            }
                        }
                    } else {
                        error = true;
                    }
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                    error = true;
                }
            } else {
                Parcelable parcelable = intent.getParcelableExtra(Intent.EXTRA_STREAM);
                if (parcelable == null) {
                    return;
                }
                String path = null;
                if (!(parcelable instanceof Uri)) {
                    parcelable = Uri.parse(parcelable.toString());
                }
                if (parcelable != null && type != null && type.startsWith("image/")) {
                    photoPath = (Uri) parcelable;
                } else {
                    path = Utilities.getPath((Uri) parcelable);
                    if (path != null) {
                        if (path.startsWith("file:")) {
                            path = path.replace("file://", "");
                        }
                        if (type != null && type.startsWith("video/")) {
                            videoPath = path;
                        } else {
                            documentPath = path;
                        }
                    } else {
                        error = true;
                    }
                }
                if (error) {
                    Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show();
                }
            }
        } else if (intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
            boolean error = false;
            try {
                ArrayList<Parcelable> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
                String type = intent.getType();
                if (uris != null) {
                    if (type != null && type.startsWith("image/")) {
                        Uri[] uris2 = new Uri[uris.size()];
                        for (int i = 0; i < uris2.length; i++) {
                            Parcelable parcelable = uris.get(i);
                            if (!(parcelable instanceof Uri)) {
                                parcelable = Uri.parse(parcelable.toString());
                            }
                            uris2[i] = (Uri) parcelable;
                        }
                        imagesPathArray = uris2;
                    } else {
                        String[] uris2 = new String[uris.size()];
                        for (int i = 0; i < uris2.length; i++) {
                            Parcelable parcelable = uris.get(i);
                            if (!(parcelable instanceof Uri)) {
                                parcelable = Uri.parse(parcelable.toString());
                            }
                            String path = Utilities.getPath((Uri) parcelable);
                            if (path != null) {
                                if (path.startsWith("file:")) {
                                    path = path.replace("file://", "");
                                }
                                uris2[i] = path;
                            }
                        }
                        documentsPathArray = uris2;
                    }
                } else {
                    error = true;
                }
            } catch (Exception e) {
                FileLog.e("tmessages", e);
                error = true;
            }
            if (error) {
                Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show();
            }
        } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            try {
                Cursor cursor = getContentResolver().query(intent.getData(), null, null, null, null);
                if (cursor != null) {
                    if (cursor.moveToFirst()) {
                        int userId = cursor.getInt(cursor.getColumnIndex("DATA4"));
                        NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
                        push_user_id = userId;
                    }
                    cursor.close();
                }
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }
        } else if (intent.getAction().equals("org.telegram.messenger.OPEN_ACCOUNT")) {
            open_settings = 1;
        }
    }

    if (getIntent().getAction() != null && getIntent().getAction().startsWith("com.tmessages.openchat")
            && (getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0 && !restore) {
        int chatId = getIntent().getIntExtra("chatId", 0);
        int userId = getIntent().getIntExtra("userId", 0);
        int encId = getIntent().getIntExtra("encId", 0);
        if (chatId != 0) {
            TLRPC.Chat chat = MessagesController.getInstance().chats.get(chatId);
            if (chat != null) {
                NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
                push_chat_id = chatId;
            }
        } else if (userId != 0) {
            TLRPC.User user = MessagesController.getInstance().users.get(userId);
            if (user != null) {
                NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
                push_user_id = userId;
            }
        } else if (encId != 0) {
            TLRPC.EncryptedChat chat = MessagesController.getInstance().encryptedChats.get(encId);
            if (chat != null) {
                NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
                push_enc_id = encId;
            }
        }
    }

    if (push_user_id != 0) {
        if (push_user_id == UserConfig.clientUserId) {
            open_settings = 1;
        } else {
            ChatActivity fragment = new ChatActivity();
            Bundle bundle = new Bundle();
            bundle.putInt("user_id", push_user_id);
            fragment.setArguments(bundle);
            if (fragment.onFragmentCreate()) {
                pushOpened = true;
                ApplicationLoader.fragmentsStack.add(fragment);
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss();
            }
        }
    } else if (push_chat_id != 0) {
        ChatActivity fragment = new ChatActivity();
        Bundle bundle = new Bundle();
        bundle.putInt("chat_id", push_chat_id);
        fragment.setArguments(bundle);
        if (fragment.onFragmentCreate()) {
            pushOpened = true;
            ApplicationLoader.fragmentsStack.add(fragment);
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss();
        }
    } else if (push_enc_id != 0) {
        ChatActivity fragment = new ChatActivity();
        Bundle bundle = new Bundle();
        bundle.putInt("enc_id", push_enc_id);
        fragment.setArguments(bundle);
        if (fragment.onFragmentCreate()) {
            pushOpened = true;
            ApplicationLoader.fragmentsStack.add(fragment);
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss();
        }
    }
    if (videoPath != null || photoPath != null || sendingText != null || documentPath != null
            || documentsPathArray != null || imagesPathArray != null || contactsToSend != null) {
        MessagesActivity fragment = new MessagesActivity();
        fragment.selectAlertString = R.string.ForwardMessagesTo;
        fragment.selectAlertStringDesc = "ForwardMessagesTo";
        fragment.animationType = 1;
        Bundle args = new Bundle();
        args.putBoolean("onlySelect", true);
        fragment.setArguments(args);
        fragment.delegate = this;
        ApplicationLoader.fragmentsStack.add(fragment);
        fragment.onFragmentCreate();
        getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, fragment.getTag())
                .commitAllowingStateLoss();
        pushOpened = true;
    }
    if (open_settings != 0) {
        SettingsActivity fragment = new SettingsActivity();
        ApplicationLoader.fragmentsStack.add(fragment);
        fragment.onFragmentCreate();
        getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "settings")
                .commitAllowingStateLoss();
        pushOpened = true;
    }
    if (!pushOpened && !isNew) {
        BaseFragment fragment = ApplicationLoader.fragmentsStack
                .get(ApplicationLoader.fragmentsStack.size() - 1);
        getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, fragment.getTag())
                .commitAllowingStateLoss();
    }

    getIntent().setAction(null);
}

From source file:com.fvd.nimbus.BrowseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
    //overridePendingTransition(R.anim.carbon_slide_in,R.anim.carbon_slide_out);
    //overridePendingTransition(R.anim.activity_open_scale,R.anim.activity_close_translate);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    try {//from   www  .j  a  v  a 2  s .c o m
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    } catch (Exception e) {
        e.printStackTrace();
    }
    clipData = new DataExchange();
    isInitNow = true;
    setContentView(R.layout.screen_browser);
    serverHelper.getInstance().setCallback(this, this);
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    lastUrl = prefs.getString("LAST_URL", "");
    saveCSS = prefs.getString("clipStyle", "1").equals("1");
    ctx = this;

    //adapter = new TextAdapter(this);      

    /*Uri data = getIntent().getData();
    if(data!=null){
       lastUrl=data.toString();
    }*/
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();
    if (Intent.ACTION_VIEW.equals(action) /*&& type != null*/) {
        Uri data = intent.getData();
        if (data != null) {
            lastUrl = data.toString();
            appSettings.appendLog("browse:onCreate  " + lastUrl);
        }
    } else if (Intent.ACTION_SEND.equals(action) /*&& type != null*/) {
        if ("text/plain".equals(type)) {
            String surl = intent.getStringExtra(Intent.EXTRA_TEXT);
            if (surl.contains(" ")) {
                String[] arr = surl.replace("\t", " ").split(" ");
                for (String s : arr) {
                    if (s.contains("://")) {
                        lastUrl = s.trim();
                        break;
                    }
                }
            } else if (surl.contains("://"))
                lastUrl = surl.trim();
            appSettings.appendLog("browse:onCreate  " + lastUrl);
        }
    }

    drawer = (DrawerLayout) findViewById(R.id.root);

    View v = findViewById(R.id.wv);
    wv = (fvdWebView) findViewById(R.id.wv);
    wv.setEventsHandler(this);
    //registerForContextMenu(wv); 
    urlField = (AutoCompleteTextView) findViewById(R.id.etAddess);
    urlField.setSelectAllOnFocus(true);
    urlField.setOnEditorActionListener(new EditText.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                /*InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);*/
                onNavButtonClicked();
                return true;
            } else if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                onNavButtonClicked();
                return true;
            }
            return false;
        }
    });
    onViewCreated();

    handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case 0:
                findViewById(R.id.bZoomStack).setVisibility(View.VISIBLE);
                findViewById(R.id.bToggleMenu).setVisibility(View.GONE);

                break;

            default:
                break;
            }
        }
    };

    navButton = (ImageButton) findViewById(R.id.ibReloadWebPage);
    navButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //Toast.makeText(getApplicationContext(), "You made a mess", Toast.LENGTH_LONG).show();
            onNavButtonClicked();
        }
    });

    findViewById(R.id.bSavePageFragment).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //toggleTools();
            floatMenu.collapse();
            if (!wv.getInjected())
                Toast.makeText(ctx, getString(R.string.wait_load), Toast.LENGTH_LONG).show();
            clipMode = 2;
            if (wv.getInjected()/* && !v.isSelected()*/) {
                wv.setCanClip(true);
                v.setSelected(true);
                Toast.makeText(ctx, ctx.getString(R.string.use_longtap), Toast.LENGTH_LONG).show();
            }

        }
    });

    (findViewById(R.id.bSaveFullPage)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            floatMenu.collapse();
            if (wv.getInjected()) {
                wv.setCanClip(false);
                wv.saveArticle();
                clipMode = 1;
                progressDialog = ProgressDialog.show(v.getContext(), "Nimbus Clipper",
                        getString(R.string.please_wait), true, false);
            } else {
                Toast.makeText(ctx, getString(R.string.wait_load), Toast.LENGTH_LONG).show();
            }
        }
    });

    findViewById(R.id.bTakeScreenshot).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //toggleTools();
            floatMenu.collapse();
            findViewById(R.id.bSaveFullPage).setVisibility(View.GONE);
            findViewById(R.id.bSavePageFragment).setVisibility(View.GONE);
            findViewById(R.id.bTakeScreenshot).setVisibility(View.GONE);
            if (wv.getInjected()) {
                wv.setCanClip(false);
            }
            findViewById(R.id.bToggleMenu).setVisibility(View.GONE);
            /*screenCapture();
            findViewById(R.id.bToggleMenu).setVisibility(View.VISIBLE);*/

            findViewById(R.id.bTakeScreenshot).postDelayed(new Runnable() {
                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    screenCapture();
                    findViewById(R.id.bToggleMenu).setVisibility(View.VISIBLE);
                    finish();
                }
            }, 10);

            //showDialog(DIALOG_CAPTURE);
        }
    });

    (findViewById(R.id.bDone)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            {
                try {

                    wv.setCanClip(false);
                    wv.endSelectionMode();
                    //findViewById(R.id.bSavePageFragment).setSelected(false);
                    clipMode = 2;
                    wv.endSelectionMode();
                    String selHtml = clipData.getContent();
                    if (selHtml.length() > 0) {
                        String ss = selHtml.substring(0, selHtml.indexOf(">") + 1).toLowerCase();
                        int j = ss.indexOf("<div");
                        if (j == 0) {
                            j = ss.indexOf("style");
                            if (j > 0) {
                                int k = ss.indexOf("\"", j + 11);
                                if (k > 0)
                                    selHtml = selHtml.replace(selHtml.substring(j, k + 1), "");
                            }
                            //selHtml="<DIV>"+selHtml.substring(ss.length());
                        }
                        clipData.setContent(selHtml);
                        clipData.setTitle(wv.getTitle());

                        /*if (true){
                                    
                            if(sessionId.length() == 0 || userPass.length()==0) showSettings();
                            else {
                               if(prefs.getBoolean("check_fast", false)){
                         sendNote(wv.getTitle(), clipData.getContent(), parent, tag);
                         clipData.setContent("");
                               }
                               else {
                               //serverHelper.getInstance().setCallback(this,this);
                               if(appSettings.sessionId.length()>0) {
                         serverHelper.getInstance().sendRequest("notes:getFolders", "","");
                         }
                               }
                            }
                            wv.endSelectionMode();
                         } */

                        Intent i = new Intent(getApplicationContext(), previewActivity.class);
                        i.putExtra("content", clipData);
                        startActivityForResult(i, 5);
                        //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
                        overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
                    }
                    //clipData.setContent("");
                } catch (Exception e) {
                    BugReporter.Send("onEndSelection", e.getMessage());
                }
            }
            //showDialog(DIALOG_CAPTURE);
        }
    });

    findViewById(R.id.bZoomIn).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            wv.ZoomInSelection();
        }
    });

    findViewById(R.id.bZoomOut).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            wv.ZoomOutSelection();
        }
    });

    setNavButtonState(NavButtonState.NBS_GO);

    progressBar = (ProgressBar) findViewById(R.id.progressbar);

    //CookieSyncManager.createInstance(this);

    //webSettings.setLoadsImagesAutomatically(imgOn);
    userMail = prefs.getString("userMail", "");
    userPass = prefs.getString("userPass", "");
    sessionId = prefs.getString("sessionId", "");

    appSettings.sessionId = sessionId;
    appSettings.userMail = userMail;
    appSettings.userPass = userPass;

    if ("1".equals(prefs.getString("userAgent", "1"))) {
        wv.setUserAgent(null);
    } else
        wv.setUserAgent(deskAgent);

    final Activity activity = this;
    //lastUrl="file:///android_asset/android.html";
    if (lastUrl.length() > 0) {
        //wv.navigate(lastUrl);

        //if(!urlField.getText().toString().equals(wv.getUrl()))
        urlField.setText(lastUrl);
        openURL();
    }
    isInitNow = false;

    urlField.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            // TODO Auto-generated method stub
            /*String item = (String)parent.getItemAtPosition(position);
                    
            Toast.makeText(
                  getApplicationContext(),
                  "  "
                + item,
                  Toast.LENGTH_SHORT).show();*/
            openURL();

        }
    });

    urlField.addTextChangedListener(this);
    parent = prefs.getString("remFolderId", "default");

    /*ListView listView = (ListView) findViewById(R.id.left_drawer);
    listView.setAdapter(new DrawerMenuAdapter(this,getResources().getStringArray(R.array.lmenu_browser)));
    listView.setOnItemClickListener(this);*/
}

From source file:im.vector.activity.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (CommonActivityUtils.shouldRestartApp()) {
        Log.e(LOG_TAG, "Restart the application.");
        CommonActivityUtils.restartApp(this);
    }//from  ww  w .j  a  v  a 2 s.  c  om

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    mMyRoomList = (ExpandableListView) findViewById(R.id.listView_myRooms);
    // the chevron is managed in the header view
    mMyRoomList.setGroupIndicator(null);
    mAdapter = new ConsoleRoomSummaryAdapter(this, Matrix.getMXSessions(this), R.layout.adapter_item_my_rooms,
            R.layout.adapter_room_section_header);

    if (null != savedInstanceState) {
        if (savedInstanceState.containsKey(PUBLIC_ROOMS_LIST_LIST)) {
            Serializable map = savedInstanceState.getSerializable(PUBLIC_ROOMS_LIST_LIST);

            if (null != map) {
                HashMap<String, List<PublicRoom>> hash = (HashMap<String, List<PublicRoom>>) map;
                mPublicRoomsListList = new ArrayList<List<PublicRoom>>(hash.values());
                mHomeServerNames = new ArrayList<>(hash.keySet());
            }
        }
    }

    final Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_JUMP_TO_ROOM_ID)) {
        mAutomaticallyOpenedRoomId = intent.getStringExtra(EXTRA_JUMP_TO_ROOM_ID);
    }

    if (intent.hasExtra(EXTRA_JUMP_MATRIX_ID)) {
        mAutomaticallyOpenedMatrixId = intent.getStringExtra(EXTRA_JUMP_MATRIX_ID);
    }

    if (intent.hasExtra(EXTRA_ROOM_INTENT)) {
        mOpenedRoomIntent = intent.getParcelableExtra(EXTRA_ROOM_INTENT);
    }

    String action = intent.getAction();
    String type = intent.getType();

    // send files from external application
    if ((Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) && type != null) {
        this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                CommonActivityUtils.sendFilesTo(HomeActivity.this, intent);
            }
        });
    }

    mMyRoomList.setAdapter(mAdapter);
    Collection<MXSession> sessions = Matrix.getMXSessions(HomeActivity.this);

    // check if  there is some valid session
    // the home activity could be relaunched after an application crash
    // so, reload the sessions before displaying the hidtory
    if (sessions.size() == 0) {
        Log.e(LOG_TAG, "Weird : onCreate : no session");

        if (null != Matrix.getInstance(this).getDefaultSession()) {
            Log.e(LOG_TAG, "No loaded session : reload them");
            startActivity(new Intent(HomeActivity.this, SplashActivity.class));
            HomeActivity.this.finish();
            return;
        }
    }

    for (MXSession session : sessions) {
        addSessionListener(session);
    }

    mMyRoomList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                long id) {

            if (mAdapter.isRecentsGroupIndex(groupPosition)) {
                String roomId = null;
                MXSession session = null;

                RoomSummary roomSummary = mAdapter.getRoomSummaryAt(groupPosition, childPosition);
                session = Matrix.getInstance(HomeActivity.this).getSession(roomSummary.getMatrixId());

                roomId = roomSummary.getRoomId();
                Room room = session.getDataHandler().getRoom(roomId);
                // cannot join a leaving room
                if ((null == room) || room.isLeaving()) {
                    roomId = null;
                }

                if (mAdapter.resetUnreadCount(groupPosition, roomId)) {
                    session.getDataHandler().getStore().flushSummary(roomSummary);
                }

                if (null != roomId) {
                    CommonActivityUtils.goToRoomPage(session, roomId, HomeActivity.this, null);
                }

            } else if (mAdapter.isPublicsGroupIndex(groupPosition)) {
                joinPublicRoom(mAdapter.getHomeServerURLAt(groupPosition),
                        mAdapter.getPublicRoomAt(groupPosition, childPosition));
            }

            return true;
        }
    });

    mMyRoomList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
                long packedPos = ((ExpandableListView) parent).getExpandableListPosition(position);
                final int groupPosition = ExpandableListView.getPackedPositionGroup(packedPos);

                if (mAdapter.isRecentsGroupIndex(groupPosition)) {
                    final int childPosition = ExpandableListView.getPackedPositionChild(packedPos);

                    FragmentManager fm = HomeActivity.this.getSupportFragmentManager();
                    IconAndTextDialogFragment fragment = (IconAndTextDialogFragment) fm
                            .findFragmentByTag(TAG_FRAGMENT_ROOM_OPTIONS);

                    if (fragment != null) {
                        fragment.dismissAllowingStateLoss();
                    }

                    final Integer[] lIcons = new Integer[] { R.drawable.ic_material_exit_to_app };
                    final Integer[] lTexts = new Integer[] { R.string.action_leave };

                    fragment = IconAndTextDialogFragment.newInstance(lIcons, lTexts, null,
                            HomeActivity.this.getResources().getColor(R.color.vector_title_color));
                    fragment.setOnClickListener(new IconAndTextDialogFragment.OnItemClickListener() {
                        @Override
                        public void onItemClick(IconAndTextDialogFragment dialogFragment, int position) {
                            Integer selectedVal = lTexts[position];

                            if (selectedVal == R.string.action_leave) {
                                HomeActivity.this.runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        final RoomSummary roomSummary = mAdapter.getRoomSummaryAt(groupPosition,
                                                childPosition);
                                        final MXSession roomSession = Matrix.getInstance(HomeActivity.this)
                                                .getSession(roomSummary.getMatrixId());

                                        String roomId = roomSummary.getRoomId();
                                        Room room = roomSession.getDataHandler().getRoom(roomId);

                                        if (null != room) {
                                            room.leave(new SimpleApiCallback<Void>(HomeActivity.this) {
                                                @Override
                                                public void onSuccess(Void info) {
                                                    mAdapter.removeRoomSummary(groupPosition, roomSummary);
                                                    mAdapter.notifyDataSetChanged();
                                                }
                                            });
                                        }
                                    }
                                });
                            }
                        }
                    });

                    fragment.show(fm, TAG_FRAGMENT_ROOM_OPTIONS);

                    return true;
                }
            }

            return false;
        }
    });

    mMyRoomList.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
        @Override
        public void onGroupExpand(int groupPosition) {
            if (mAdapter.isPublicsGroupIndex(groupPosition)) {
                refreshPublicRoomsList();
            }
        }
    });

    mMyRoomList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
        @Override
        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
            return mAdapter.getGroupCount() < 2;
        }
    });

    mSearchRoomEditText = (EditText) this.findViewById(R.id.editText_search_room);
    mSearchRoomEditText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(android.text.Editable s) {
            mAdapter.setSearchedPattern(s.toString());
            mMyRoomList.smoothScrollToPosition(0);
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
}

From source file:com.iiordanov.runsoft.bVNC.RemoteCanvasActivity.java

void initialize() {
    if (android.os.Build.VERSION.SDK_INT >= 9) {
        android.os.StrictMode.ThreadPolicy policy = new android.os.StrictMode.ThreadPolicy.Builder().permitAll()
                .build();/*  ww w.j  a  va  2 s  .  co m*/
        android.os.StrictMode.setThreadPolicy(policy);
    }

    handler = new Handler();

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    database = new Database(this);

    Intent i = getIntent();
    connection = null;

    Uri data = i.getData();

    Log.e(TAG, "uri=" + data);

    boolean isSupportedScheme = false;
    if (data != null) {
        String s = data.getScheme();
        isSupportedScheme = s.equals("rdp") || s.equals("spice") || s.equals("vnc");
    }

    if (isSupportedScheme || !Utils.isNullOrEmptry(i.getType())) {
        if (isMasterPasswordEnabled()) {
            Utils.showFatalErrorMessage(this,
                    getResources().getString(R.string.master_password_error_intents_not_supported));
            return;
        }

        connection = ConnectionBean.createLoadFromUri(data, this);

        String host = data.getHost();
        if (!host.startsWith(Constants.CONNECTION)) {
            connection.parseFromUri(data);
        }

        if (connection.isSaved()) {
            connection.saveAndWriteRecent(false);
        }
        // we need to save the connection to display the loading screen, onclso otherwise we should exit
        if (!connection.isReadyForConnection()) {
            if (!connection.isSaved()) {
                Log.i(TAG, "Exiting - Insufficent information to connect and connection was not saved.");
                Toast.makeText(this, getString(R.string.error_uri_noinfo_nosave), Toast.LENGTH_LONG).show();
                ;
            } else {
                // launch bVNC activity
                Log.i(TAG, "Insufficent information to connect, showing connection dialog.");
                Intent bVncIntent = new Intent(this, bVNC.class);
                startActivity(bVncIntent);
            }
            finish();
            return;
        }
    } else {
        connection = new ConnectionBean(this);
        Bundle extras = i.getExtras();

        if (extras != null) {
            connection.Gen_populate((ContentValues) extras.getParcelable(Constants.CONNECTION));
        }

        // Parse a HOST:PORT entry
        String host = connection.getAddress();
        if (!Utils.isValidIpv6Address(host) && host.indexOf(':') > -1) {
            String p = host.substring(host.indexOf(':') + 1);
            try {
                int parsedPort = Integer.parseInt(p);
                connection.setPort(parsedPort);
                connection.setAddress(host.substring(0, host.indexOf(':')));
            } catch (Exception e) {
            }
        }

        if (connection.getPort() == 0)
            connection.setPort(Constants.DEFAULT_VNC_PORT);

        if (connection.getSshPort() == 0)
            connection.setSshPort(Constants.DEFAULT_SSH_PORT);
    }
}

From source file:pt.aptoide.backupapps.Aptoide.java

private void handleIncomingIntent(Intent incomingIntent) {
    if (incomingIntent.getData() != null) {
        AptoideLog.d(this, "received intent: " + incomingIntent.getDataString());
        if (incomingIntent.getType() != null && incomingIntent.getType().equals(Constants.MIMETYPE_MYAPP)) {
            AptoideLog.d(this, "received myapp: " + incomingIntent.getDataString());
            try {
                serviceDataCaller.callReceiveMyapp(incomingIntent.getDataString());
            } catch (RemoteException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();//  w w  w . jav a2s  .c o  m
            }
        } else if (incomingIntent.getScheme().equals(Constants.SCHEME_MARKET)
                || (incomingIntent.getScheme().equals(Constants.SCHEME_HTTPS)
                        && incomingIntent.getData().getHost().equals(Constants.HOST_MARKET))) {
            String query = incomingIntent.getData().getQuery().split("&")[0].split("=")[1];
            if (query.contains(":")) {
                query = query.split(":")[1];
            }
            AptoideLog.d(this, "received market query: " + query);
            if (!synchronizingInstalledApps.get()) {
                startSearch(query, false, null, false);
            } else {
                blockedSearchQuery = query;
            }
        }

        cleanAptoideIntent();
    }
}