Skip to content
This repository has been archived by the owner on May 28, 2020. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lizhaotailang committed Mar 31, 2017
1 parent 630d5bf commit 9f22b2a
Show file tree
Hide file tree
Showing 18 changed files with 511 additions and 152 deletions.
28 changes: 0 additions & 28 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ dependencies {
// Google Mobile Service
compile 'com.google.android.gms:play-services:10.2.1'
// Support libraries
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:support-v4:25.3.0'
compile 'com.android.support:design:25.3.0'
compile 'com.android.support:cardview-v7:25.3.0'
compile 'com.android.support:preference-v14:25.3.0'
compile 'com.android.support:customtabs:25.3.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:preference-v14:25.3.1'
compile 'com.android.support:customtabs:25.3.1'
// ReactiveX series
compile 'io.reactivex.rxjava2:rxjava:2.0.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
Expand All @@ -34,15 +33,13 @@
import android.support.design.widget.TextInputEditText;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.inputmethod.InputMethodManager;
import android.widget.ProgressBar;

Expand Down Expand Up @@ -70,7 +67,6 @@ public class AddPackageFragment extends Fragment
private AppCompatTextView textViewScanCode;
private FloatingActionButton fab;
private ProgressBar progressBar;
private NestedScrollView scrollView;

private AddPackageContract.Presenter presenter;

Expand Down Expand Up @@ -99,8 +95,6 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,

initViews(view);

addLayoutListener(scrollView, editTextName);

fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down Expand Up @@ -166,32 +160,6 @@ public void onPause() {
presenter.unsubscribe();
}

/**
* Scroll the screen to avoid edit text being covered by imm such as the soft keyboard.
* It is better to set the height as 150 because some devices
* has the navigation bar. The height 100 might not trigger the scrolling action.
* @param main The scroll view.
* @param scroll The view to show.
*/
private void addLayoutListener(final View main, final View scroll) {
main.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect rect = new Rect();
main.getWindowVisibleDisplayFrame(rect);
int mainInvisibleHeight = main.getRootView().getHeight() - rect.bottom;
if (mainInvisibleHeight > 150) {
int[] location = new int[2];
scroll.getLocationInWindow(location);
int scrollHeight = (location[1] + scroll.getHeight()) - rect.bottom;
main.scrollTo(0, scrollHeight);
} else {
main.scrollTo(0, 0);
}
}
});
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
Expand All @@ -217,8 +185,6 @@ public void initViews(View view) {
textViewScanCode = (AppCompatTextView) view.findViewById(R.id.textViewScanCode);
fab = (FloatingActionButton) view.findViewById(R.id.fab);
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
scrollView = (NestedScrollView) view.findViewById(R.id.scrollView);

}

/**
Expand Down
36 changes: 18 additions & 18 deletions mobile/src/main/res/layout/fragment_add_package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,26 @@

</android.support.design.widget.AppBarLayout>

<FrameLayout
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/app_bar_height" >
android:layout_height="wrap_content"
android:id="@+id/scrollView"
android:scrollbars="vertical"
android:scrollbarFadeDuration="1"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fadeScrollbars="true">

<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:visibility="gone"
android:indeterminate="true" />
android:layout_height="match_parent">

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView"
android:scrollbars="vertical"
android:scrollbarFadeDuration="1"
android:fadeScrollbars="true">
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:visibility="gone"
android:indeterminate="true" />


<LinearLayout
Expand Down Expand Up @@ -130,9 +130,9 @@

</LinearLayout>

</android.support.v4.widget.NestedScrollView>
</FrameLayout>

</FrameLayout>
</android.support.v4.widget.NestedScrollView>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
Expand Down
1 change: 1 addition & 0 deletions mobile/src/main/res/layout/item_package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
android:layout_height="wrap_content"
android:id="@+id/textViewPackageName"
android:maxLines="1"
android:ellipsize="end"
android:textColor="@color/colorPrimaryText"
android:textAppearance="@style/TextAppearance.AppCompat.Body2" />

Expand Down
2 changes: 1 addition & 1 deletion wear/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:2.0.0'
compile 'com.google.android.gms:play-services-wearable:10.2.0'
compile 'com.google.android.gms:play-services-wearable:10.2.1'
}
36 changes: 25 additions & 11 deletions wear/src/main/java/io/github/marktony/espresso/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,37 @@

import android.app.Activity;
import android.os.Bundle;
import android.support.wearable.view.WatchViewStub;
import android.widget.TextView;
import android.support.wearable.view.DefaultOffsettingHelper;
import android.support.wearable.view.WearableRecyclerView;

public class MainActivity extends Activity {
import java.util.ArrayList;
import java.util.List;

import io.github.marktony.espresso.data.Package;

private TextView mTextView;
public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {
mTextView = (TextView) stub.findViewById(R.id.text);
}
});

List<Package> list = new ArrayList<>();
Package p1 = new Package();
p1.setName("SF");
list.add(p1);

Package p2 = new Package();
p2.setName("YUNDA");
list.add(p2);

WearableRecyclerView recyclerView = (WearableRecyclerView) findViewById(R.id.recyclerView);
recyclerView.setCenterEdgeItems(true);

recyclerView.setOffsettingHelper(new DefaultOffsettingHelper());

PackageRecyclerAdapter adapter = new PackageRecyclerAdapter(list);
recyclerView.setAdapter(adapter);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright(c) 2017 lizhaotailang
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.marktony.espresso;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.support.wearable.view.CircledImageView;
import android.support.wearable.view.WearableRecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import io.github.marktony.espresso.data.Package;

/**
* Created by lizhaotailang on 2017/3/31.
*/

public class PackageRecyclerAdapter extends WearableRecyclerView.Adapter<RecyclerView.ViewHolder> {

private final List<Package> mList;

public PackageRecyclerAdapter(@NonNull List<Package> list) {
mList = list;
}

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_package, parent, false));
}

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
Package p = mList.get(position);
ViewHolder vh = (ViewHolder) holder;
if (p != null) {
vh.textViewAvatar.setText(p.getName().substring(0, 1));
vh.textViewName.setText(p.getName());
if (p.getData() != null && p.getData().size() > 0) {
vh.textViewStatus.setText(p.getData().get(0).getContext());
} else {
vh.textViewStatus.setText("Can not get the latest status.");
}
}
}

@Override
public int getItemCount() {
return mList.size();
}

public class ViewHolder extends WearableRecyclerView.ViewHolder {

private TextView textViewAvatar;
private TextView textViewName;
private TextView textViewStatus;
private CircledImageView avatar;

public ViewHolder(View itemView) {
super(itemView);
textViewAvatar = (TextView) itemView.findViewById(R.id.textViewAvatar);
textViewName = (TextView) itemView.findViewById(R.id.textViewName);
textViewStatus = (TextView) itemView.findViewById(R.id.textViewStatus);
avatar = (CircledImageView) itemView.findViewById(R.id.avatar);
}
}

}
Loading

0 comments on commit 9f22b2a

Please sign in to comment.