package com.chery.wearosdemo;
import android.os.Bundle;
import android.support.wearable.activity.WearableActivity;
import android.view.View;
import androidx.recyclerview.widget.RecyclerView;
import androidx.wear.widget.WearableLinearLayoutManager;
import androidx.wear.widget.WearableRecyclerView;
import java.util.ArrayList;
import java.util.List;publicclassMainActivity extends WearableActivity {privateWearableRecyclerView wearableRecyclerView;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initView();// Enables Always-onsetAmbientEnabled();}privatevoidinitView(){
wearableRecyclerView =(WearableRecyclerView)findViewById(R.id.recycler_launcher_view);
List<String> datas =newArrayList<>();for(int i =0; i <7; i++){
datas.add(""+ i);}CustomScrollingLayoutCallback customScrollingLayoutCallback =newCustomScrollingLayoutCallback();
wearableRecyclerView.setLayoutManager(newWearableLinearLayoutManager(this,customScrollingLayoutCallback));// To align the edge children (first and last) with the center of the screen
wearableRecyclerView.setEdgeItemsCenteringEnabled(true);
wearableRecyclerView.setAdapter(newMyAdapter(this, datas));}publicclassCustomScrollingLayoutCallback extends WearableLinearLayoutManager.LayoutCallback {/** How much should we scale the icon at most. */privatestatic final float MAX_ICON_PROGRESS =0.65f;
@OverridepublicvoidonLayoutFinished(View child,RecyclerView parent){// Figure out % progress from top to bottom.float centerOffset =(child.getHeight()/2.0f)/ parent.getHeight();float yRelativeToCenterOffset =(child.getY()/ parent.getHeight())+ centerOffset;// Normalize for center.float progressToCenter = Math.abs(0.5f- yRelativeToCenterOffset);// Adjust to the maximum scale.
progressToCenter = Math.min(progressToCenter, MAX_ICON_PROGRESS);
child.setScaleX(1- progressToCenter);
child.setScaleY(1- progressToCenter);}}}