Triple check that, will ya?

device-2017-03-08-124806A long long time ago
I can still remember how
That App used to make me smile….
And I knew if I had my chance
That I could make those dice dance
And maybe they’d be happy for a while….

Uh, wrong lyrics. Actually, it was quite a while ago that I made the Android app, Ships, Captain, and Crew! After the move from GitHub to GitLab, I decided to look over some of my old issues that were imported with GitLab’s great import tool. Among them, I found two issues for this old app that I had made.

The first was that of an issue with screen rotation causing the app to restart. I quickly fixed that by just setting the activity to portrait mode in the manifest file. You can check my commit if you need details.

The second issue was a bit more complicated, in that there was a problem with checking the dice for a ship, captain, or crew. Essentially, if you rolled a 4, 5, 6, 1, and 3, it would say you only have a ship (the 6) and no captain (5) or crew (4). Obviously that’s wrong. The issue is that you need a 6 before you can keep a 5 or 4. And since the dice were checked in order, when it looked at the 5 or 4, it did not have a 6 yet, so they were not “kept”.

This is how I fixed it:

for (int i = 0; i < 3; i++) {

// Check three times.

myNumber = firstDie;

diceCheck();

if (waschecked){

firstnotchecked = false;

}

dieOne.setImageResource(id);

myNumber = secondDie;

diceCheck();

if (waschecked){

secondnotchecked = false;

}

dieTwo.setImageResource(id);

myNumber = thirdDie;

diceCheck();

if (waschecked){

thirdnotchecked = false;

}

dieThree.setImageResource(id);

myNumber = fourthDie;

diceCheck();

if (waschecked){

fourthnotchecked = false;

}

dieFour.setImageResource(id);

myNumber = fifthDie;

diceCheck();

if (waschecked){

fifthnotchecked = false;

}


dieFive.setImageResource(id);


}

As you can see,  I told it to check the dice, first to last, three times. Yes, this is ugly and poor programming. Actually, I was almost ashamed of this early work, it looked so congested and terrible. However, my goal today was the quick fix, so that’s what I did. Hopefully, the update will be available on F-Droid soon, so you’ll have to check it out!

Linux – keep it simple.

Advertisements

Game restarts when minimized!

When I originally created JustChess, I had a problem. If you were playing a game, and pressed the new game button, then started another game, you could press back and go back to the menu, then back and go back to the game. This was a bit odd. At the time, I solved it with “Intent.FLAG_ACTIVITY_NO_HISTORY”. This worked great. Too great.

The problem, as pointed out on my issue tracker, was that when you minimized the game, it would be “destroyed” and rebuilt when you brought the app back. Which is not cool. You may need to answer a text and then come back to your game, and it shouldn’t disappear in between!

minimized

So, I fixed it with my latest commit. I took out the FLAG_ACTIVITY_NO_HISTORY intents, but then my original problem returned. To solve that, I added “finish()” to my new game button, like so:

// First you define it.
Intent myintent = new Intent(MainActivity.this, IntroActivity.class);
// Now you call it.
startActivity(myintent);
finish();

}
})

Now, when you select a new game, it “finishes” your old one. Pressing the back button doesn’t lead you on a wild goose chase to dozens of old games, it just brings you back to the main menu, and that’s much better!

Linux – keep it simple.

Can’t play chess in landscape mode!

Another one of the great issues brought up by a user of JustChess, my simple chess playing Android app, was the fact that when the screen was rotated, you can’t see the bottom half of the board!

Realistically, this would require one of two things:

  1. Fixed portrait mode, not allowing the user to rotate the screen.
  2. Having a separate layout that was appropriate for the rotated screen.

But instead I chose option number 3: Add a scroll view!

Option 1 would limit users from being able to hold their phone a different way if it was more comfortable, and that doesn’t solve any problems, it just limits use.

Option 2 is the proper way to fix this, but I’m done working on this app right now, and involved in other project. This would be a bit of an overhaul, and would take me a considerable amount of time.

Option 3, is cheating. I am adding a scroll view so that the user who wants to play in landscape view can scroll the board to recenter it on the screen. This is fine for hi-res screens we see today, but may be a problem on an older phone, where the user would have to scroll the board back and forth to see all of it.

slide

Either way, you can see the full commit on my GitLab, but here is the pertinent part of the code, in the layout xml file:

<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <LinearLayout
...... edited for space .......
    </LinearLayout>
</ScrollView>

This neatly wraps everything up into a nested scroll view which the user can move by swiping. This may also help if in portrait mode on an older phone with a very small screen.

Linux – keep it simple.

Video Tutorial for Building Android: Advanced Topics

twrp
Praise God! Another video series featuring more advanced material!
Previously, I had created a video tutorial and guide for how to compile Android, from Lollipop through Marshmallow, Nougat, and Oreo. If you need help learning the basics or intermediate material, please see my other video tutorial thread on XDA, Or here on my website through the navigation bar at the top.

Who is this video series for?
Well, this video tutorial is a guide built primarily for the intermediate Android developer. This is written for those who already know how to compile custom roms for a phone that they own using device trees and vendor files that are already available. Things like using git, GitHub, GitLab, ADB, fastboot, and repo sync should already be something familiar to them.

That said, I believe that an intermediate developer will find this set of videos to be most helpful. The goal of this video series is to push the intermediate developer up to a rudimentary advanced level.

Advanced developer?
An advanced rom/kernel developer will probably far exceed my feeble abilities, and will not likely find much useful information here. Perhaps if you are an advanced developer, you would consider making another tutorial or adding to this advanced video series! (See further posts for recommendations on contributing videos.) Please! I’d really like to add links to your YouTube channel, or your git repository full of advanced topics for developers! Help up the quality of devices and builds of Android by showing others what you know how to do best!

Why did you put this together?
Well, after releasing the previous tutorial, explaining to beginners how to use things like git, repo sync, compile roms, and do small kernel modification, it was brought to my attention that a more advanced course was needed for intermediate users who already know how to build roms, but may (like myself) struggle with more complicated tasks. I don’t know how to do everything, and we all have to take the next step sometime, so why not take that next step together?

What’s in the videos?
During the series, we will be attempting several more advanced tasks. At present, there is not a lot in the series, but below are some of the highlights from what is available.

Section A: Building a device tree from scratch:
+ Research
+ Finding similar devices
+ Pulling vendor files
+ Setting up a device tree
+ Getting block device information
+ Pulling kernel information
+ Breaking down boot images
+ Build errors
+ Target Assets
+ Tombstones AND MORE!

**** This is an UNOFFICIAL TUTORIAL. Use at your own risk! ****
Now including more than 4 hours of video!

Download links: The video quality is now 1080p!

Ogg Vorbis Video GitLab:
https://gitlab.com/alaskalinuxuser/advanced_course_android_developer_guide
Clicking on a video in GitLab will allow you to watch it online.

Ogg Vorbis Video Downloads:
https://gitlab.com/alaskalinuxuser/advanced_course_android_developer_guide/-/archive/master/advanced_course_android_developer_guide-master.zip
This download is rather large due to the multiple videos.

MP4 Video GitLab:
https://gitlab.com/alaskalinuxuser/advanced_course_android_developer_guide_mp4
Clicking on a video in GitLab will allow you to watch it online.

MP4 Video Downloads:
https://gitlab.com/alaskalinuxuser/advanced_course_android_developer_guide_mp4/-/archive/master/advanced_course_android_developer_guide_mp4-master.zip
This download is rather large due to the multiple videos.

Youtube links: The Youtube quality is now 1080p!
https://www.youtube.com/watch?v=5c66tBsiVVM&list=PLRJ9-cX1yE1nnhWBrZtuVz5YC2OPfQVVp
I am uploading videos. I do have slow internet, so please be patient. Only a portion of videos are uploaded at this time. Upping the quality of the videos have significantly slowed down my ability to upload them.
My device and kernel trees (GitLab) : https://gitlab.com/alaskalinuxuser/

Linux – keep it simple.

The game restarts on screen rotation!

After my JustChess app hit the F-Droid repository, I was pleasantly surprised to hear that people were trying it out! With every wave of players, however, came a new wave of issues. I like issues. I’m a bit of a problem solver, so it gives me a clear direction to work towards.

One of the issues was that rotating the screen caused the current game to be destroyed and restarted. Of course! I should have thought about that. Since I sold my Android phones, I was using the emulator to finish building this game. With the emulator, I didn’t consider screen rotation!

Fortunately, the first fix is pretty simple. If your activity restarts on rotation, then you should add this line to your manifest for each activity:

android:configChanges="orientation|screenSize"

Like this:

<activity
    android:name=".MainActivity"
    android:configChanges="orientation|screenSize"
    android:label="@string/app_name"
    android:theme="@style/AppTheme.NoActionBar" />

You can check out the full commit on my GitLab, but that is all you need to fix this issue. Now I just need to make it playable when the screen is rotated!

rotating

Linux – keep it simple.

Cancel all notifications!

While trying to update and add features to my old open source Hourglass app, I decided that the issue posted asking for a notification cancel button was a pretty good idea!

Screenshot from 2018-05-02 13-12-03

Now you can cancel your timer at any time from the notification bar! The code was pretty simple, actually, and you can read the entire commit on my GitLab, but here is the important part:

// as a result of notification action
Intent detailsIntent = new Intent(MainActivity.this, CancelActivity.class);
detailsIntent.putExtra("EXTRA_DETAILS_ID", 42);
PendingIntent detailsPendingIntent = PendingIntent.getActivity(
      MainActivity.this,
      0,
      detailsIntent,
      PendingIntent.FLAG_UPDATE_CURRENT
      );

NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
        .setSmallIcon(R.drawable.hourglass).setWhen(System.currentTimeMillis()+recureTime).setUsesChronometer(true)
        .setContentTitle("Hourglass").setContentText(intentPhrase).addAction(
                android.R.drawable.ic_notification_clear_all, "Cancel", detailsPendingIntent);

Intent intent = new Intent(context, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pIntent = PendingIntent.getActivity(context, 0 , intent, PendingIntent.FLAG_UPDATE_CURRENT);

This mumbo jumbo just allows the cancel button to be displayed, which, if pressed, calls the CancelActivity class.

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

    // Set the screen orientation to portrait to keep the screen rotation bug from stoping
    // the timer on some phones.
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    // Just log.
    Log.i("WJH", "CancellAll.");
    allCancel = true;
    finish();

}

The moment the CancelActivity.java class opens, it set’s the boolean allCancel to true (meaning yes, we want to cancel) and exits back to the MainActivity class, where the timer is running.

Then, on every tick of the timer, it checks to see if allCancel is true or false. If true, it cancels the timer, repeating timer, and recurring alarm. If false, it continues to count down as usual. Praise God! It actually works! Be sure to check out revision 1.9 of the app for this latest feature! And thanks to “brunetton” for the great idea!

Linux – keep it simple.

BlueFruit autostart was a success!

image20180531_074506688

After several series of bench tests, I was finally ready to make the plunge and install my home made autostart into my truck. The vehicle in question is a 1993 GMC K3500 pickup truck. It took about 30 minutes to remove the lower dash portion and properly identify the wires in question. Then, about 15 minutes later, the whole thing was hooked up.

Then came the scary moment of truth.

I opened my app on my phone, and pressed the big orange start button.

The first set of relays engaged, turning on ignition power, fuel pump power, etc. So far so good. After the 5 second delay (purposefully programmed to allow the priming of the fuel) the second set of relays kicked in, the vehicle cranked, and STARTED!

To God be the glory! Wow! I can’t believe it actually worked! Lo and behold, pushing the stop button on my app killed the truck too! Great! By the way, the entire project, all files, apps, sketches, pictures, etc., can be downloaded from the repository I made for this on GitLab.

A few tests showed that I still have some fine tuning to do. As can be seen from the two issues I opened on the repository, there are two enhancements that really would make this better. The first is that the range is limited to about 30 feet, on a good day with nothing between you and the truck. The second is a slight problem with voltage detection for determining if the vehicle is started.

You see, I am using a voltage divider to break down the 12+ vdc to less than 3 vdc for the BlueFruit board. If it is less than 0.9 volts on the board (13 volts on the vehicle), then the alternator is not charging and the vehicle must not be running. This causes a few problems.

  1. If the vehicle’s alternator ever fails, the autostart will attempt to start a running truck numerous times.
  2. During the cranking process, the board keeps checking voltage to see if the engine started, but it will always read low when a huge load like the starter is engaged. So it will always crank the full 3 seconds of crank time, even if the vehicle is started.

Both of these conditions will cause excessive wear on the starter, and in general is just poor design. So I’ll be thinking on a way to make that better. In any event, I’m really glad that the initial run was a success!

Linux – keep it simple.

Update to Rom/Kernel/TWRP building guide!

Hey everyone!

Just wanted to let you know that I was able to finish and upload another hour worth of videos! That’s right, currently there is more than 9 hours of video tutorial available. As promised, this was added to the series:

* Installing/using VirtualBox
* Fixing a VB Ubuntu problem with screen resolution
* Syncing minimal LineageOS or Omni for building TWRP
* Converting an Omni TWRP device to LineageOS/CM and building it.
* Custom TWRP mods with fonts/icons/splash screens/etc….

twrp

Hope that you are enjoying the series, but mostly, I hope that it is informative and gets you building!
I did try to up the video quality, but I had to tone it back down a bit, as the files became a bit large for uploading and handling. The quality is a little better than the first videos, but not exactly 1080p! 

Thanks again for all of the thanks button slaps and YouTube subscriptions. That lets me know that you guys really appreciate the videos. Be sure to check out my Video Tutorial section in the menu for links to the videos!

Linux – keep it simple.

Can you say that again, Mr. Alarm?

While using my Hourglass app for Android phones, a user made an interesting observation:

Hi
I love this open source app and using it quite often. But sometimes my phone is in my pocket and I’m listening to music and I miss the time ended notification ! The vibration is short, easy to miss, same thing for the notifications sounds. I’d find “logical” to have a continuous notification that vibrates and rings until I manually stop it (from notification bar or inside app).
Is this feature planned for a future release ?
Thanks

What a great idea! I’m glad that “bruneton” opened this issue on my issue tracker. That’s part of the beauty of open source. Sure, closed source programs could take input as well, but the open source community encourages and enables it, as well as giving others the code so that they can make changes themselves!

So, I added another button:

time_up

And with that button, some new code, which you can check out in full from the commit on my GitLab, but here is the gist of it:

– // Cancel the notification.
 – mNotificationManager.cancel(0);

 – // Set the time bar back to usable.
 – timeBar.setEnabled(true);
 + if (alreYes) {
 +
 + startCount(2000,1000);
 +
 + } else {
 + // Cancel the notification.
 + mNotificationManager.cancel(0);
 +
 + // Set the time bar back to usable.
 + timeBar.setEnabled(true);
 + }

What we have here, is a repeating timer that, if the continuous alarm is set, will “repeat” by resetting the countdown to 2 seconds, over and over again, until you cancel the repeating alarm!

It seems to work well so far, but I think I can do better. So, I’m looking at adding a “Stop” or “Cancel” option to the notification pop up. We’ll see, but for now, it does repeat rather nicely!

Linux – keep it simple.

Putting Android Nougat on a Nook HD+

While there are several guides out there on how to do this, I ran into a slight snag while trying to put Android Nougat on a Nook HD+, so I thought I’d share that with you. I was following this guide: https://nookhdplusandroid7.wordpress.com/

Following through the instructions seemed to go very smoothly, until it didn’t work. Specifically, after putting in the micro SD card, and powering off the device, powering it on would just cause a blank screen. Then, several minutes later, the device would turn on as normal.

Turns out that the Nook just didn’t like my SD card. It was a 4 GB card that I had laying around. When I opened a new package of 16 GB PNY SD cards, the whole process started working.

I don’t want to rehash the excellent write up that was already given, but I thought I would share my small issue, in case someone else runs into that problem. Turns out, there are some newer roms available for the Nook HD+ as well.

Either way, here are a couple of screen shots about showing the outcome:

It seems to work rather nicely. I did notice one slight “glitch” to the screen when I selected MTP for the USB mode, but other than that, it seems to work great! Now I just have to force myself to give it back to it’s owner!

Linux – keep it simple.