下面列出了android.widget.ImageView#setOnFocusChangeListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMediaProjectionManager = (MediaProjectionManager)
getSystemService(Context.MEDIA_PROJECTION_SERVICE);
ImageView iv = findViewById(R.id.power_toggle);
iv.setOnClickListener(this);
iv.setOnFocusChangeListener(this);
iv.setFocusable(true);
iv.requestFocus();
setImageViews(mRecorderRunning, false);
LocalBroadcastManager.getInstance(this).registerReceiver(
mMessageReceiver, new IntentFilter(HyperionScreenService.BROADCAST_FILTER));
checkForInstance();
}
private void initActivity() {
// assume the recorder is not running until we are notified otherwise
mRecorderRunning = false;
setContentView(R.layout.activity_main);
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
mMediaProjectionManager = (MediaProjectionManager)
getSystemService(Context.MEDIA_PROJECTION_SERVICE);
ImageView iv = findViewById(R.id.power_toggle);
iv.setOnClickListener(this);
iv.setOnFocusChangeListener(this);
iv.setFocusable(true);
iv.requestFocus();
ImageButton ib = findViewById(R.id.settingsButton);
ib.setOnClickListener(this);
ib.setOnFocusChangeListener(this);
ib.setFocusable(true);
setImageViews(mRecorderRunning, false);
LocalBroadcastManager.getInstance(this).registerReceiver(
mMessageReceiver, new IntentFilter(BROADCAST_FILTER));
// request an update on the running status
checkForInstance();
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mAllAppsHandle = (ImageView) findViewById(R.id.all_apps_handle);
mAllAppsHandle.setImageDrawable(getCaretDrawable());
mAllAppsHandle.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
mAllAppsHandle.setOnClickListener(mLauncher);
mAllAppsHandle.setOnLongClickListener(mLauncher);
mAllAppsHandle.setOnFocusChangeListener(mLauncher.mFocusHandler);
mLauncher.setAllAppsButton(mAllAppsHandle);
}
/**
* Set up the dashboard of buttons to launch the various services of the
* app. This covers things like touch/focus listeners, authentication,
* intent to launch, etc.
*/
private void setupDashBoardButtons() {
scheduleCheck = (ImageView) findViewById(R.id.scheduleCheck);
balanceCheck = (ImageView) findViewById(R.id.balanceCheck);
dataCheck = (ImageView) findViewById(R.id.dataCheck);
ProgressBar scheduleProgress = (ProgressBar) findViewById(R.id.scheduleProgress);
ProgressBar balanceProgress = (ProgressBar) findViewById(R.id.balanceProgress);
ProgressBar dataProgress = (ProgressBar) findViewById(R.id.dataProgress);
final Intent schedule = new Intent(this, ScheduleActivity.class);
final Intent balance = new Intent(this, BalanceActivity.class);
final Intent map = new Intent(this, CampusMapActivity.class);
final Intent data = new Intent(this, DataUsageActivity.class);
final Intent menu = new Intent(this, MenuActivity.class);
DashboardButtonData buttonData[] = new DashboardButtonData[6];
buttonData[0] = new DashboardButtonData(schedule, R.id.schedule_button, authCookie,
scheduleCheck, scheduleProgress, !loginFailed);
buttonData[1] = new DashboardButtonData(balance, R.id.balance_button, authCookie,
balanceCheck, balanceProgress, !loginFailed);
buttonData[2] = new DashboardButtonData(data, R.id.data_button, authCookie,
dataCheck, dataProgress, !loginFailed);
buttonData[3] = new DashboardButtonData(map, R.id.map_button);
buttonData[4] = new DashboardButtonData(menu, R.id.menu_button);
featureButtons = new ImageView[5];
for (int i = 0; i < 5; i++) {
ImageView ib = (ImageView) findViewById(buttonData[i].imageButtonId);
ib.setOnTouchListener(new ImageButtonTouchListener(
(TransitionDrawable) ib.getDrawable()));
ib.setOnFocusChangeListener(new ImageButtonFocusListener());
ib.setTag(buttonData[i]);
if (buttonData[i].enabled) {
enableFeature(ib);
} else {
disableFeature(ib);
}
featureButtons[i] = ib;
}
}