Example usage for android.view View FOCUS_DOWN

List of usage examples for android.view View FOCUS_DOWN

Introduction

In this page you can find the example usage for android.view View FOCUS_DOWN.

Prototype

int FOCUS_DOWN

To view the source code for android.view View FOCUS_DOWN.

Click Source Link

Document

Use with #focusSearch(int) .

Usage

From source file:de.storyquest.client.ContentActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // enable immersive mode
    getWindow().getDecorView()/*from w w  w .  jav a 2 s . c  o  m*/
            .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

    // load initial layout
    setContentView(R.layout.activity_content);
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    View header = navigationView.getHeaderView(0);

    // apply theme
    try {
        Drawable d = Drawable.createFromStream(getAssets().open("sidebar.jpg"), null);
        navigationView.setBackground(d);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    // wire the drawer open event to the character sheet refresh
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer != null) {
        drawer.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                execJavaScriptInCharactersheet("if(typeof refresh!='undefined')refresh()");
            }
        });
    }

    // get extra data with bookmark to load
    Intent intent = getIntent();
    if (intent.hasExtra(BOOKMARKID))
        bookmarkId = intent.getStringExtra(BOOKMARKID);

    // set the cover image from assets
    ImageView coverImage = (ImageView) header.findViewById(R.id.coverImage);
    try {
        InputStream ims = getAssets().open("cover.png");
        Drawable d = Drawable.createFromStream(ims, null);
        coverImage.setImageDrawable(d);
    } catch (Exception e) {
        throw new RuntimeException("Error loading cover image. Is 'cover.png' available in assets?", e);
    }

    // make the web content debuggable from external chrome tools
    WebView.setWebContentsDebuggingEnabled(true);

    // enable script interfaces
    scriptSystem = new ScriptSystem(this);
    scriptStorage = new ScriptStorage(this,
            getApplicationContext().getSharedPreferences(ScriptStorage.CONTEXT, Context.MODE_PRIVATE));
    scriptSound = new ScriptSound(this);
    scriptGameServices = new ScriptGameServices(this);

    // setup character webview
    character = (WebView) header.findViewById(R.id.characterView);
    character.getSettings().setJavaScriptEnabled(true);
    character.getSettings().setDomStorageEnabled(true);
    character.getSettings().setAllowFileAccess(true);
    character.getSettings().setAppCacheEnabled(true);
    character.addJavascriptInterface(scriptSystem, "sqSystem");
    character.addJavascriptInterface(scriptStorage, "nativeStorage");
    character.addJavascriptInterface(scriptSound, "sqSound");
    character.addJavascriptInterface(scriptGameServices, "sqGameServices");
    character.loadUrl("file:///android_asset/character.html");

    // setup web view
    web = (WebView) findViewById(R.id.webView);
    web.getSettings().setJavaScriptEnabled(true);
    web.getSettings().setDomStorageEnabled(true);
    web.getSettings().setAllowFileAccess(true);
    web.getSettings().setAppCacheEnabled(true);
    web.addJavascriptInterface(scriptSystem, "sqSystem");
    web.addJavascriptInterface(scriptStorage, "nativeStorage");
    web.addJavascriptInterface(scriptSound, "sqSound");
    web.addJavascriptInterface(scriptGameServices, "sqGameServices");

    // adding event overrides for the web view
    web.setWebChromeClient(new WebChromeClient());
    web.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String urlText) {
            if (urlText.startsWith("http")) { // Could be cleverer and use a regex
                Log.d(LOGTAG, "Opening standard web intent window for " + urlText);
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(urlText));
                startActivity(i);
                return true;
            } else {
                Log.d(LOGTAG, "Loading in webview: " + urlText);
                web.loadUrl(urlText);
                return true;
            }
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            Log.d(LOGTAG, "Page rendering started: " + url + ".");
            displaySpinner(R.string.loading);
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            Log.d(LOGTAG, "Page rendering finished: " + url + ".");
            hideSpinner();
            if (bookmarkId != null && url.startsWith("file:///android_asset/content.html")) {
                Log.i(LOGTAG, "Loading bookmark " + bookmarkId + ".");
                execJavaScriptInContent("loadBookmark('" + bookmarkId + "')");
                bookmarkId = null;
            }
            super.onPageFinished(view, url);
        }

        @Override
        public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
            Log.d(LOGTAG, "Intercepted call: " + url + ".");
            return null;
        }
    });
    web.setWebChromeClient(new WebChromeClient() {
        public boolean onConsoleMessage(ConsoleMessage cm) {
            Log.d(LOGTAG, cm.message() + " - from line " + cm.lineNumber() + " of " + cm.sourceId());
            return true;
        }
    });
    web.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    web.requestFocus(View.FOCUS_DOWN);

    // finally loading content bootstrap
    Log.i(LOGTAG, "Loading index.html");
    web.loadUrl("file:///android_asset/index.html");
}

From source file:cn.jasonlv.siri.activity.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // ??? ???/*  w  w w  . j a v  a 2s  . co m*/
    musicManager = new MusicManager(getApplicationContext());

    // ??
    initImageLoader(getApplicationContext());

    /* get the installed package list*/
    // ??
    mPackageManager = new NativePackageManager(getApplicationContext());

    // ?
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // ?
    mSynthesizer = new Synthesizer(getApplicationContext());

    //mSynthesizer.speak("EDI");

    //  ?
    mContactManager = new ContactsManager(getApplicationContext());

    mContactManager.getContactList();

    // ??
    detactor = new LocationDetactor(getApplicationContext());
    info = detactor.getLocationInfo();

    Log.d("location info", info.lat + ", " + info.lon);

    //for(Object o : mPackageManager.getPackageList()){
    //    System.out.println(o.toString());

    setContentView(R.layout.sdk2_api);

    //txtLog = (TextView) findViewById(R.id.txtLog);
    btn = (ActionButton) findViewById(R.id.btn);

    // ?
    speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this,
            new ComponentName(this, VoiceRecognitionService.class));

    speechRecognizer.setRecognitionListener(this);

    btn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
            boolean api = sp.getBoolean("api", false);
            if (api) {
                switch (status) {
                case STATUS_None:
                    start();
                    //btn.setText("?");
                    status = STATUS_WaitingReady;
                    break;
                case STATUS_WaitingReady:
                    cancel();
                    status = STATUS_None;
                    //btn.setText("");
                    break;
                case STATUS_Ready:
                    cancel();
                    status = STATUS_None;
                    //btn.setText("");
                    break;
                case STATUS_Speaking:
                    stop();
                    status = STATUS_Recognition;
                    //btn.setText("");
                    break;
                case STATUS_Recognition:
                    cancel();
                    status = STATUS_None;
                    //btn.setText("");
                    break;
                }
            } else {
                start();
            }
        }
    });

    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayShowTitleEnabled(true);

    container = (LinearLayout) findViewById(R.id.container);
    scrollView = (ScrollView) findViewById(R.id.scroll);

    scrollView.fullScroll(View.FOCUS_DOWN);
}

From source file:com.yangtsaosoftware.pebblemessenger.activities.SetupFragment.java

private void test_pebble_app(Context context) {
    BroadcastReceiver br = new BroadcastReceiver() {
        @Override/*w  w w .  j  ava 2s .  c  o m*/
        public void onReceive(Context context, Intent intent) {

            byte[] command = intent.getByteArrayExtra(Constants.BROADCAST_VERSION);
            boolean result = true;
            if (command == null || command[0] < Constants.PEBBLE_VERSION[0]) {
                result = false;
            } else if (command[1] < Constants.PEBBLE_VERSION[1]) {
                result = false;
            } else if (command[2] < Constants.PEBBLE_VERSION[2]) {
                result = false;
            }
            SpannableStringBuilder ssb = new SpannableStringBuilder();
            ssb.append(textInfo.getText());
            ssb.append(context.getString(R.string.setup_app_test));
            ssb.append('\n');
            ssb.append(context.getString(R.string.setup_install_pebble_app));
            ssb.append((result ? greenText(R.string.setup_check_ok) : redText(R.string.setup_check_bad)));
            ssb.append('\n');
            textInfo.setText(ssb);
            svMyview.fullScroll(View.FOCUS_DOWN);
            LocalBroadcastManager.getInstance(context).unregisterReceiver(this);
        }
    };
    IntentFilter intentFilter = new IntentFilter(SetupFragment.class.getName());
    LocalBroadcastManager.getInstance(context).registerReceiver(br, intentFilter);
    Intent inner_intent = new Intent(PebbleCenter.class.getName());
    inner_intent.putExtra(Constants.BROADCAST_COMMAND, Constants.BROADCAST_PEBBLE_TEST);
    LocalBroadcastManager.getInstance(context).sendBroadcast(inner_intent);
}

From source file:com.discord.chipsview.ChipsView.java

public void addChip(String displayName, Uri avatarUrl, K key, V data, boolean isIndelible) {
    Chip<K, V> chip = new Chip<>(displayName, avatarUrl, key, data, isIndelible,
            new Chip.ChipParams(mChipsBgColorClicked, mDensity, mChipsBgRes, mChipsBgColor, mChipsTextColor,
                    mChipsPlaceholderResId, mChipsDeleteResId, mChipsTextColorClicked, mChipsColorClicked,
                    mChipsColor, CHIP_HEIGHT, mChipLayout),
            this);
    mChipList.put(key, chip);//from  w ww .j  av  a2  s  . c o m
    if (mChipAddedListener != null) {
        mChipAddedListener.onChipAdded(chip.getData());
    }

    onChipsChanged(true);
    post(new Runnable() {
        @Override
        public void run() {
            ChipsView.this.fullScroll(View.FOCUS_DOWN);
        }
    });
}

From source file:com.levien.audiobuffersize.AudioBufferSize.java

synchronized void log(String text) {
    msgLog += text + "\n";
    final TextView tv = (TextView) findViewById(R.id.textView1);
    //tv.setText(msgLog);
    tv.append(text + "\n");
    final ScrollView sv = (ScrollView) findViewById(R.id.scrollView);
    sv.fullScroll(View.FOCUS_DOWN);
}

From source file:com.microsoft.windowsazure.mobileservices.LoginManager.java

/**
 * Creates the UI for the interactive authentication process
 * //from   w w w  .j a v a2  s .c  o m
 * @param provider
 *            The provider used for the authentication process
 * @param startUrl
 *            The initial URL for the authentication process
 * @param endUrl
 *            The final URL for the authentication process
 * @param context
 *            The context used to create the authentication dialog
 * @param callback
 *            Callback to invoke when the authentication process finishes
 */
private void showLoginUI(final String startUrl, final String endUrl, final Context context,
        LoginUIOperationCallback callback) {
    if (startUrl == null || startUrl == "") {
        throw new IllegalArgumentException("startUrl can not be null or empty");
    }

    if (endUrl == null || endUrl == "") {
        throw new IllegalArgumentException("endUrl can not be null or empty");
    }

    if (context == null) {
        throw new IllegalArgumentException("context can not be null");
    }

    final LoginUIOperationCallback externalCallback = callback;
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    // Create the Web View to show the login page
    final WebView wv = new WebView(context);
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            if (externalCallback != null) {
                externalCallback.onCompleted(null, new MobileServiceException("User Canceled"));
            }
        }
    });
    wv.getSettings().setJavaScriptEnabled(true);

    DisplayMetrics displaymetrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int webViewHeight = displaymetrics.heightPixels;

    wv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, webViewHeight));

    wv.requestFocus(View.FOCUS_DOWN);
    wv.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) {
                if (!view.hasFocus()) {
                    view.requestFocus();
                }
            }

            return false;
        }
    });

    // Create a LinearLayout and add the WebView to the Layout
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(wv);

    // Add a dummy EditText to the layout as a workaround for a bug
    // that prevents showing the keyboard for the WebView on some devices
    EditText dummyEditText = new EditText(context);
    dummyEditText.setVisibility(View.GONE);
    layout.addView(dummyEditText);

    // Add the layout to the dialog
    builder.setView(layout);

    final AlertDialog dialog = builder.create();

    wv.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // If the URL of the started page matches with the final URL
            // format, the login process finished
            if (isFinalUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(url, null);
                }

                dialog.dismiss();
            }

            super.onPageStarted(view, url, favicon);
        }

        // Checks if the given URL matches with the final URL's format
        private boolean isFinalUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(endUrl);
        }

        // Checks if the given URL matches with the start URL's format
        private boolean isStartUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(startUrl);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (isStartUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(null, new MobileServiceException(
                            "Logging in with the selected authentication provider is not enabled"));
                }

                dialog.dismiss();
            }
        }
    });

    wv.loadUrl(startUrl);
    dialog.show();
}

From source file:fr.cobaltians.cobalt.fragments.CobaltFragment.java

protected void setWebViewSettings(Object javascriptInterface) {
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
        mWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD)
        mWebView.setOverScrollMode(View.OVER_SCROLL_IF_CONTENT_SCROLLS);
    mWebView.setScrollListener(this);
    mWebView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);

    // Enables JS
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    // Enables and setups JS local storage
    webSettings.setDomStorageEnabled(true);
    webSettings.setDatabaseEnabled(true);
    //@deprecated since API 19. But calling this method have simply no effect for API 19+
    webSettings.setDatabasePath(mContext.getFilesDir().getParentFile().getPath() + "/databases/");

    // Enables cross-domain calls for Ajax
    allowAjax();/*  ww  w . j  a  va  2  s  . co  m*/

    // Fix some focus issues on old devices like HTC Wildfire
    // keyboard was not properly showed on input touch.
    mWebView.requestFocus(View.FOCUS_DOWN);
    mWebView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!view.hasFocus()) {
                    view.requestFocus();
                }
                break;
            default:
                break;
            }

            return false;
        }
    });

    // Add JavaScript interface so JavaScript can call native functions.
    mWebView.addJavascriptInterface(javascriptInterface, "Android");
    mWebView.addJavascriptInterface(new LocalStorageJavaScriptInterface(mContext), "LocalStorage");

    WebViewClient webViewClient = new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            executeWaitingCalls();
        }
    };

    mWebView.setWebViewClient(webViewClient);
}

From source file:app.wz.MainActivity.java

public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.menu_run_pause) {
        if (neuro.halt) {
            neuro.halt = false;//from w w w  .j ava2 s.co  m
            setProgressBarIndeterminateVisibility(true);

            wakeLock.acquire();

            if (prefs.getBoolean("use_server", false))
                lock.acquire();

            // for the system's orientation sensor registered listeners
            mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
                    SensorManager.SENSOR_DELAY_GAME);

            synchronized (neuro) {
                neuro.notify();
            }
        } else {

            haltNeuro();
        }
    } else {
        if (!neuro.halt) {
            haltNeuro();
        }
    }

    if (id == R.id.menu_device_connect) {
        bt.setDeviceTarget(BluetoothState.DEVICE_OTHER);
        /*
        if(bt.getServiceState() == BluetoothState.STATE_CONNECTED)
         bt.disconnect();*/
        Intent intent = new Intent(getApplicationContext(), DeviceList.class);
        startActivityForResult(intent, BluetoothState.REQUEST_CONNECT_DEVICE);
    } else if (id == R.id.reset_Neuro) {
        neuro.updatePrefs(true);
        textRead.append("Reset Neuro \n");
        textScroll.fullScroll(View.FOCUS_DOWN);
    } else if (id == R.id.menu_disconnect) {
        if (bt.getServiceState() == BluetoothState.STATE_CONNECTED)
            bt.disconnect();
    } else if (id == R.id.remote_control) {
        if (bt.getServiceState() == BluetoothState.STATE_CONNECTED) {
            Intent intent = new Intent(this, JoystickActivity.class);
            startActivity(intent);
        } else {
            Toast.makeText(getApplicationContext(), "Not Connected", Toast.LENGTH_SHORT).show();
        }
        return true;
    } else if (id == R.id.action_settings) {
        Intent intent = new Intent(this, SettingsActivity.class);
        startActivity(intent);
        return true;
    } else if (id == R.id.help) {
        LayoutInflater li = LayoutInflater.from(this);
        View view = li.inflate(R.layout.help, null);
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setView(view);
        alert.show();
    }
    return super.onOptionsItemSelected(item);
}

From source file:org.cobaltians.cobalt.fragments.CobaltFragment.java

protected void setWebViewSettings(CobaltFragment javascriptInterface) {
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
        mWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD)
        mWebView.setOverScrollMode(View.OVER_SCROLL_IF_CONTENT_SCROLLS);
    mWebView.setScrollListener(this);
    mWebView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);

    // Enables JS
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    // Enables and setups JS local storage
    webSettings.setDomStorageEnabled(true);
    webSettings.setDatabaseEnabled(true);
    //@deprecated since API 19. But calling this method have simply no effect for API 19+
    webSettings.setDatabasePath(mContext.getFilesDir().getParentFile().getPath() + "/databases/");

    // Enables cross-domain calls for Ajax
    allowAjax();/*  w w w  .jav  a 2s  .  co m*/

    // Fix some focus issues on old devices like HTC Wildfire
    // keyboard was not properly showed on input touch.
    mWebView.requestFocus(View.FOCUS_DOWN);
    mWebView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!view.hasFocus()) {
                    view.requestFocus();
                }
                break;
            default:
                break;
            }

            return false;
        }
    });

    //Enable Webview debugging from chrome desktop
    if (Cobalt.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    // Add JavaScript interface so JavaScript can call native functions.
    mWebView.addJavascriptInterface(javascriptInterface, "Android");
    mWebView.addJavascriptInterface(new LocalStorageJavaScriptInterface(mContext), "LocalStorage");

    WebViewClient webViewClient = new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            executeWaitingCalls();
        }
    };

    mWebView.setWebViewClient(webViewClient);
}

From source file:com.albertcbraun.cms50fw.alert.MainUIFragment.java

void writeMessage(long timeStamp, final String s) {
    final Date d = new Date(timeStamp);
    messageWindow.post(new Runnable() {
        @Override/*  w ww  . j a v  a 2  s .  c o  m*/
        public void run() {
            String text = messageWindow.getText().toString();
            if (text.length() > MAX_MESSAGE_WINDOW_CHARS) {
                messageWindow.setText(text.substring(LOWER_INDEX_MESSAGE_WINDOW_CHARS, text.length() - 1));
            }
            messageWindow.append(NEWLINE + LEFT_BRACKET + DATE_FORMAT.format(d) + RIGHT_BRACKET + s);
            messageWindowScrollView.post(new Runnable() {
                public void run() {
                    messageWindowScrollView.fullScroll(View.FOCUS_DOWN);
                }
            });

        }
    });
}