-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using stateListDrawable for the bit on/off drawable. Let us change th…
…e bit with the view state
- Loading branch information
Showing
4 changed files
with
105 additions
and
64 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
26 changes: 15 additions & 11 deletions
26
app/src/main/java/com/example/binaryclock/SettingsActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,37 @@ | ||
package com.example.binaryclock; | ||
|
||
import android.graphics.drawable.Drawable; | ||
import android.graphics.drawable.GradientDrawable; | ||
import android.graphics.drawable.ShapeDrawable; | ||
import android.graphics.drawable.StateListDrawable; | ||
import android.graphics.drawable.shapes.RoundRectShape; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.view.animation.GridLayoutAnimationController; | ||
import android.widget.Button; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
public class SettingsActivity extends AppCompatActivity { | ||
private boolean state = true; | ||
private int num = 0; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_settings); | ||
|
||
Button sw = findViewById(R.id.button); | ||
sw.setOnClickListener(new View.OnClickListener() { | ||
TextView tv_number = findViewById(R.id.num); | ||
tv_number.setText(""+num); | ||
|
||
Button change = findViewById(R.id.change); | ||
change.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
ImageView bit = findViewById(R.id.d12); | ||
if (state){ | ||
bit.setBackgroundDrawable(getDrawable(R.drawable.bit_off)); | ||
} | ||
else{ | ||
bit.setBackgroundDrawable(getDrawable(R.drawable.bit_on)); | ||
} | ||
state = !state; | ||
View bit = findViewById(R.id.d00); | ||
bit.setActivated(!bit.isActivated()); | ||
} | ||
}); | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:constantSize="true" | ||
android:variablePadding="false"> | ||
<item android:state_activated="true" | ||
android:drawable="@drawable/bit_on" /> <!-- bit on --> | ||
<item android:drawable="@drawable/bit_off" /> <!-- default - bit off --> | ||
</selector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters