Example usage for android.os Message obtain

List of usage examples for android.os Message obtain

Introduction

In this page you can find the example usage for android.os Message obtain.

Prototype

public static Message obtain(Handler h, int what) 

Source Link

Document

Same as #obtain() , but sets the values for both target and what members on the Message.

Usage

From source file:com.aincc.libtest.activity.flip.FlipViewGroup.java

/**
 *      ? UIThread .
 * 
 * @since 1.0.0
 */
public void requestPopulate() {
    handler.sendMessage(Message.obtain(handler, MSG_POPULATE));
}

From source file:net.pmarks.chromadoze.NoiseService.java

public void updatePercentAsync(int percent) {
    mPercentHandler.removeMessages(PERCENT_MSG);
    Message m = Message.obtain(mPercentHandler, PERCENT_MSG);
    m.arg1 = percent;/*from w ww  . j a  va  2  s  . co m*/
    m.sendToTarget();
}

From source file:org.smilec.smile.student.CourseList.java

public void setNewStateFromTeacher(int todo_number) { // called by junction object

    messageHandler.sendMessage(Message.obtain(messageHandler, todo_number));
    // below Handler will be called soon enough with 'todo_number' as
    // msg.what//w  w w  .jav a  2  s .c  om
}

From source file:org.altusmetrum.AltosDroid.AltosDroid.java

private void onTimerTick() {
    try {
        mMessenger.send(Message.obtain(null, MSG_UPDATE_AGE));
    } catch (RemoteException e) {
    }
}

From source file:de.androvdr.activities.AndroVDR.java

public void initWorkspaceView(Bundle savedInstanceState) {
    if (!Preferences.alternateLayout)
        setTheme(R.style.Theme_Original);

    logger.debug("Model: {}", Build.MODEL);
    logger.debug("SDK Version: {}", Build.VERSION.SDK_INT);

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    logger.debug("Width: {}", metrics.widthPixels);
    logger.debug("Height: {}", metrics.heightPixels);
    logger.debug("Density: {}", metrics.densityDpi);

    Configuration conf = getResources().getConfiguration();
    boolean screenSmall = ((conf.screenLayout
            & Configuration.SCREENLAYOUT_SIZE_SMALL) == Configuration.SCREENLAYOUT_SIZE_SMALL);
    boolean screenNormal = ((conf.screenLayout
            & Configuration.SCREENLAYOUT_SIZE_NORMAL) == Configuration.SCREENLAYOUT_SIZE_NORMAL);
    boolean screenLong = ((conf.screenLayout
            & Configuration.SCREENLAYOUT_LONG_YES) == Configuration.SCREENLAYOUT_LONG_YES);
    boolean screenLarge = ((conf.screenLayout
            & Configuration.SCREENLAYOUT_SIZE_LARGE) == Configuration.SCREENLAYOUT_SIZE_LARGE);
    boolean screenXLarge = ((conf.screenLayout
            & Configuration.SCREENLAYOUT_SIZE_XLARGE) == Configuration.SCREENLAYOUT_SIZE_XLARGE);

    logger.debug("Screen Small: {}", screenSmall);
    logger.debug("Screen Normal: {}", screenNormal);
    logger.debug("Screen Long: {}", screenLong);
    logger.debug("Screen Large: {}", screenLarge);
    logger.debug("Screen XLarge: {}", screenXLarge);

    if (screenSmall)
        Preferences.screenSize = Preferences.SCREENSIZE_SMALL;
    if (screenNormal)
        Preferences.screenSize = Preferences.SCREENSIZE_NORMAL;
    if (screenLong)
        Preferences.screenSize = Preferences.SCREENSIZE_LONG;
    if (screenLarge)
        Preferences.screenSize = Preferences.SCREENSIZE_LARGE;
    if (screenXLarge)
        Preferences.screenSize = Preferences.SCREENSIZE_XLARGE;
    logger.trace("Screen size: {}", Preferences.screenSize);

    // --- init default text size for buttons ---
    TextResizeButton.resetDefaultTextSize();
    TextResizeButton rb = (TextResizeButton) LayoutInflater.from(this).inflate(R.layout.reference_button, null);
    if ((Preferences.screenSize >= Preferences.SCREENSIZE_LARGE)
            && (metrics.widthPixels > metrics.heightPixels))
        rb.setTextSizeAsDefault(metrics.widthPixels / 2 / 5, 100);
    else//from  w w w. j  av  a  2 s .co  m
        rb.setTextSizeAsDefault(Math.min(metrics.widthPixels, metrics.heightPixels) / 4, 100);
    logger.debug("Default TextSize (px): {}", rb.getTextSize());

    // --- landscape mode only on large displays ---
    if (Preferences.screenSize < Preferences.SCREENSIZE_LARGE) {
        logger.trace("setting SCREEN_ORIENTATION_PORTRAIT");
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    setContentView(R.layout.remote_pager);
    mPagerAdapter = new PagerAdapter(getSupportFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);

    LinePageIndicator indicator = (LinePageIndicator) findViewById(R.id.titles);
    if (mPagerAdapter.getCount() > 1) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        int last = sp.getInt("remote_last_page", 0);
        if (last < mPagerAdapter.getCount())
            indicator.setViewPager(mPager, last);
        else
            indicator.setViewPager(mPager);
    } else {
        indicator.setVisibility(View.GONE);
    }

    // --- show current channel in status bar ---
    if (Preferences.screenSize < Preferences.SCREENSIZE_XLARGE)
        mDevices.addOnSensorChangeListener("VDR.channel", 1, new OnSensorChangeListener() {
            @Override
            public void onChange(String result) {
                logger.trace("Channel: {}", result);
                Message msg = Message.obtain(mSensorHandler, SENSOR_CHANNEL);
                Bundle bundle = new Bundle();
                bundle.putString(MSG_RESULT, result);
                msg.setData(bundle);
                msg.sendToTarget();
            }
        });

    mDevices.startSensorUpdater(0);
}

From source file:by.zatta.pilight.MainActivity.java

@Override
public void onServiceConnected(ComponentName name, IBinder service) {
    mServiceMessenger = new Messenger(service);
    try {//  ww w .  j av  a  2 s . co m
        Message msg = Message.obtain(null, ConnectionService.MSG_REGISTER_CLIENT);
        msg.replyTo = mMessenger;
        mServiceMessenger.send(msg);
    } catch (RemoteException e) {
        // In this case the service has crashed before we could even do
        // anything with it
    }
}

From source file:most.voip.example.ws_config.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case R.id.action_quit:
        if (this.voipHandler != null) {
            Message m = Message.obtain(this.voipHandler, -1);
            m.sendToTarget();// w w w  .j a  va 2s .  c o m
            break;
        } else {
            Log.d(TAG, "Exiting app");
            finish();
            Runtime.getRuntime().gc();
            android.os.Process.killProcess(android.os.Process.myPid());
        }
    default:
        break;
    }

    return true;
}

From source file:org.navitproject.navit.NavitDownloadSelectMapActivity.java

private void askForMapDeletion(final String map_location) {
    AlertDialog.Builder deleteMapBox = new AlertDialog.Builder(this);
    deleteMapBox.setTitle(Navit.getInstance().getTstring(R.string.map_delete));
    deleteMapBox.setCancelable(true);/*from   w  ww . j av a2  s .  com*/

    NavitMap maptoDelete = new NavitMap(map_location);
    deleteMapBox
            .setMessage(maptoDelete.mapName + " " + String.valueOf(maptoDelete.size() / 1024 / 1024) + "MB");

    // TRANS
    deleteMapBox.setPositiveButton(Navit.getInstance().getTstring(R.string.yes),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    Log.d(TAG, "Delete Map");
                    Message msg = Message.obtain(Navit.getInstance().getNavitGraphics().callback_handler,
                            NavitGraphics.msg_type.CLB_DELETE_MAP.ordinal());
                    Bundle b = new Bundle();
                    b.putString("title", map_location);
                    msg.setData(b);
                    msg.sendToTarget();
                    finish();
                }
            });

    // TRANS
    deleteMapBox.setNegativeButton((Navit.getInstance().getTstring(R.string.no)),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    Log.d(TAG, "don't delete map");
                }
            });
    deleteMapBox.show();
}

From source file:com.example.helloworldlinked.backend.HelloWorldService.java

public void sendAccessoryNotificationMessage(NotificationModel notification) {
    if (notification == null) {
        Utility.logWarning(TAG, "Not sending null notification");
        return;//from   ww w.ja va 2 s.  co  m
    }
    Message message = Message.obtain(null, MSG_NOTIFICATION);
    Bundle bundle = notification.createBundle();
    message.setData(bundle);
    sendToProviderService(message);
}

From source file:com.smithdtyler.prettygoodmusicplayer.NowPlaying.java

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

    Intent originIntent = getIntent();/*  w w w .  j  a va2  s.com*/
    if (originIntent.getBooleanExtra("From_Notification", false)) {

        String artistName = originIntent.getStringExtra(ArtistList.ARTIST_NAME);
        String artistAbsPath = originIntent.getStringExtra(ArtistList.ARTIST_ABS_PATH_NAME);
        if (artistName != null && artistAbsPath != null) {
            Log.i(TAG, "Now Playing was launched from a notification, setting up its back stack");
            // Reference: https://developer.android.com/reference/android/app/TaskStackBuilder.html
            TaskStackBuilder tsb = TaskStackBuilder.create(this);
            Intent intent = new Intent(this, ArtistList.class);
            tsb.addNextIntent(intent);

            intent = new Intent(this, AlbumList.class);
            intent.putExtra(ArtistList.ARTIST_NAME, artistName);
            intent.putExtra(ArtistList.ARTIST_ABS_PATH_NAME, artistAbsPath);
            tsb.addNextIntent(intent);

            String albumName = originIntent.getStringExtra(AlbumList.ALBUM_NAME);
            if (albumName != null) {
                intent = new Intent(this, SongList.class);
                intent.putExtra(AlbumList.ALBUM_NAME, albumName);
                intent.putExtra(ArtistList.ARTIST_NAME, artistName);
                intent.putExtra(ArtistList.ARTIST_ABS_PATH_NAME, artistAbsPath);
                tsb.addNextIntent(intent);
            }
            intent = new Intent(this, NowPlaying.class);
            tsb.addNextIntent(intent);
            tsb.startActivities();
        }

    }

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    String theme = sharedPref.getString("pref_theme", getString(R.string.light));
    String size = sharedPref.getString("pref_text_size", getString(R.string.medium));
    Log.i(TAG, "got configured theme " + theme);
    Log.i(TAG, "got configured size " + size);

    // These settings were fixed in english for a while, so check for old style settings as well as language specific ones.
    if (theme.equalsIgnoreCase(getString(R.string.dark)) || theme.equalsIgnoreCase("dark")) {
        Log.i(TAG, "setting theme to " + theme);
        if (size.equalsIgnoreCase(getString(R.string.small)) || size.equalsIgnoreCase("small")) {
            setTheme(R.style.PGMPDarkSmall);
        } else if (size.equalsIgnoreCase(getString(R.string.medium)) || size.equalsIgnoreCase("medium")) {
            setTheme(R.style.PGMPDarkMedium);
        } else {
            setTheme(R.style.PGMPDarkLarge);
        }
    } else if (theme.equalsIgnoreCase(getString(R.string.light)) || theme.equalsIgnoreCase("light")) {
        Log.i(TAG, "setting theme to " + theme);
        if (size.equalsIgnoreCase(getString(R.string.small)) || size.equalsIgnoreCase("small")) {
            setTheme(R.style.PGMPLightSmall);
        } else if (size.equalsIgnoreCase(getString(R.string.medium)) || size.equalsIgnoreCase("medium")) {
            setTheme(R.style.PGMPLightMedium);
        } else {
            setTheme(R.style.PGMPLightLarge);
        }
    }

    boolean fullScreen = sharedPref.getBoolean("pref_full_screen_now_playing", false);
    currentFullScreen = fullScreen;
    if (fullScreen) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    } else {
        ActionBar actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    setContentView(R.layout.activity_now_playing);

    if (savedInstanceState == null) {
        doBindService(true);
        startPlayingRequired = true;
    } else {
        doBindService(false);
        startPlayingRequired = false;
    }

    // Get the message from the intent
    Intent intent = getIntent();
    if (intent.getBooleanExtra(KICKOFF_SONG, false)) {
        desiredArtistName = intent.getStringExtra(ArtistList.ARTIST_NAME);
        desiredAlbumName = intent.getStringExtra(AlbumList.ALBUM_NAME);
        desiredArtistAbsPath = intent.getStringExtra(ArtistList.ARTIST_ABS_PATH_NAME);
        desiredSongAbsFileNames = intent.getStringArrayExtra(SongList.SONG_ABS_FILE_NAME_LIST);
        desiredAbsSongFileNamesPosition = intent.getIntExtra(SongList.SONG_ABS_FILE_NAME_LIST_POSITION, 0);
        desiredSongProgress = intent.getIntExtra(MusicPlaybackService.TRACK_POSITION, 0);

        Log.d(TAG,
                "Got song names " + desiredSongAbsFileNames + " position " + desiredAbsSongFileNamesPosition);

        TextView et = (TextView) findViewById(R.id.artistName);
        et.setText(desiredArtistName);

        et = (TextView) findViewById(R.id.albumName);
        et.setText(desiredAlbumName);
    }

    // The song name field will be set when we get our first update update from the service.

    final ImageButton pause = (ImageButton) findViewById(R.id.playPause);
    pause.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            playPause();
        }

    });

    ImageButton previous = (ImageButton) findViewById(R.id.previous);
    previous.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            previous();
        }

    });

    previous.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            jumpBack();
            return true;
        }
    });

    ImageButton next = (ImageButton) findViewById(R.id.next);
    next.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            next();
        }
    });

    final ImageButton shuffle = (ImageButton) findViewById(R.id.shuffle);
    shuffle.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            toggleShuffle();
        }
    });

    final ImageButton jumpback = (ImageButton) findViewById(R.id.jumpback);
    jumpback.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            jumpBack();
        }
    });

    SeekBar seekBar = (SeekBar) findViewById(R.id.songProgressBar);
    seekBar.setEnabled(true);
    seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        private int requestedProgress;

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                Log.v(TAG, "drag location updated..." + progress);
                this.requestedProgress = progress;
                updateSongProgressLabel(progress);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            NowPlaying.this.userDraggingProgress = true;

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            Message msg = Message.obtain(null, MusicPlaybackService.MSG_SEEK_TO);
            msg.getData().putInt(MusicPlaybackService.TRACK_POSITION, requestedProgress);
            try {
                Log.i(TAG, "Sending a request to seek!");
                mService.send(msg);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
            NowPlaying.this.userDraggingProgress = false;
        }

    });

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction("com.smithdtyler.ACTION_EXIT");
    exitReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            Log.i(TAG, "Received exit request, shutting down...");
            Intent msgIntent = new Intent(getBaseContext(), MusicPlaybackService.class);
            msgIntent.putExtra("Message", MusicPlaybackService.MSG_STOP_SERVICE);
            startService(msgIntent);
            finish();
        }

    };
    registerReceiver(exitReceiver, intentFilter);
}