Skip to content

Commit

Permalink
- Fix bug for "match_parent" layout compass
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed Radhouane Belkilani committed May 13, 2018
1 parent 884d104 commit b673b67
Show file tree
Hide file tree
Showing 19 changed files with 24 additions and 57 deletions.
Binary file added .gradle/4.6/fileContent/fileContent.lock
Binary file not shown.
Binary file modified .gradle/4.6/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/4.6/fileHashes/fileHashes.lock
Binary file not shown.
Binary file added .gradle/4.6/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file added .gradle/4.6/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file added .gradle/4.6/javaCompile/jarAnalysis.bin
Binary file not shown.
Binary file added .gradle/4.6/javaCompile/javaCompile.lock
Binary file not shown.
Binary file added .gradle/4.6/javaCompile/taskHistory.bin
Binary file not shown.
Binary file added .gradle/4.6/javaCompile/taskJars.bin
Binary file not shown.
Binary file modified .gradle/4.6/taskHistory/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/4.6/taskHistory/taskHistory.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
16 changes: 1 addition & 15 deletions app/src/main/java/edu/arbelkilani/compassview/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,13 @@
import edu.arbelkilani.compass.Compass;
import edu.arbelkilani.compass.CompassListener;

public class MainActivity extends AppCompatActivity implements CompassListener {
public class MainActivity extends AppCompatActivity {

private final static String TAG = MainActivity.class.getSimpleName();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Compass compass = findViewById(R.id.compass_3);
compass.setListener(this);
}

@Override
public void onSensorChanged(SensorEvent event) {
Log.d(TAG, "onSensorChanged : " + event);
}

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
Log.d(TAG, "onAccuracyChanged : sensor : " + sensor);
Log.d(TAG, "onAccuracyChanged : accuracy : " + accuracy);
}
}
42 changes: 2 additions & 40 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,8 @@
android:padding="20dp"
tools:context=".MainActivity">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<edu.arbelkilani.compass.Compass
android:id="@+id/compass_1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
app:degree_color="@color/blue"
app:degrees_step="5"
app:needle="@drawable/ic_needle_2"
app:orientation_labels_color="@color/red"
app:show_degree_value="false"
app:show_orientation_labels="true" />

<edu.arbelkilani.compass.Compass
android:id="@+id/compass_2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignBaseline="@+id/compass_1"
android:layout_alignParentEnd="true"
android:layout_marginTop="40dp"
app:degrees_step="45"
app:show_border="true"
app:show_degree_value="true"
app:show_orientation_labels="false" />

</RelativeLayout>

<edu.arbelkilani.compass.Compass
android:id="@+id/compass_3"
android:layout_width="270dp"
android:layout_height="270dp"
android:layout_marginTop="20dp"
app:degree_color="@color/colorPrimary"
app:needle="@drawable/ic_needle_1"
app:orientation_labels_color="@color/colorAccent"
app:show_degree_value="true"
app:show_orientation_labels="true" />
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</LinearLayout>
9 changes: 9 additions & 0 deletions compass/src/main/java/edu/arbelkilani/compass/Compass.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ public Compass(Context context, @Nullable AttributeSet attrs, int defStyleAttr)
init(context, attrs);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (widthMeasureSpec < heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
} else {
super.onMeasure(heightMeasureSpec, heightMeasureSpec);
}
}

private void init(Context context, AttributeSet attrs) {
LayoutInflater.from(context).inflate(R.layout.compass_layout, this, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ private void init(Context context, AttributeSet attrs) {
Log.d("TAG", "init function");
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (widthMeasureSpec < heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
} else {
super.onMeasure(heightMeasureSpec, heightMeasureSpec);
}
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Expand Down
2 changes: 1 addition & 1 deletion compass/src/main/res/layout/compass_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
android:id="@+id/compass_skeleton"
android:background="@android:color/transparent">


<ImageView
android:id="@+id/iv_needle"
android:src="@drawable/ic_needle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"/>
Expand Down
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Sun May 13 23:57:16 CET 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

0 comments on commit b673b67

Please sign in to comment.