Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day3 HMOS assignment - Jawahar #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions HarmonyOS/Day3 Assingment/Jawahar Venugopal/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
/entry/.preview
.cxx
3 changes: 3 additions & 0 deletions HarmonyOS/Day3 Assingment/Jawahar Venugopal/.idea/.gitignore

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

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

22 changes: 22 additions & 0 deletions HarmonyOS/Day3 Assingment/Jawahar Venugopal/.idea/gradle.xml

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

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

4 changes: 4 additions & 0 deletions HarmonyOS/Day3 Assingment/Jawahar Venugopal/.idea/misc.xml

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

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

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

37 changes: 37 additions & 0 deletions HarmonyOS/Day3 Assingment/Jawahar Venugopal/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'com.huawei.ohos.app'

ohos {
compileSdkVersion 5
defaultConfig {
compatibleSdkVersion 5
}
}

buildscript {
repositories {
maven {
url 'https://repo.huaweicloud.com/repository/maven/'
}
maven {
url 'https://developer.huawei.com/repo/'
}
jcenter()
}
dependencies {
classpath 'com.huawei.ohos:hap:2.4.4.2'
classpath 'com.huawei.ohos:decctest:1.0.0.7'
}
}

allprojects {
repositories {
maven {
url 'https://repo.huaweicloud.com/repository/maven/'
}
maven {
url 'https://developer.huawei.com/repo/'
}
jcenter()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
29 changes: 29 additions & 0 deletions HarmonyOS/Day3 Assingment/Jawahar Venugopal/entry/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apply plugin: 'com.huawei.ohos.hap'
apply plugin: 'com.huawei.ohos.decctest'
ohos {
compileSdkVersion 5
defaultConfig {
compatibleSdkVersion 5
}
compileOptions {
annotationEnabled true
}
buildTypes {
release {
proguardOpt {
proguardEnabled false
rulesFiles 'proguard-rules.pro'
}
}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
testImplementation 'junit:junit:4.13'
ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100'
}
decc {
supportType = ['html', 'xml']
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# config module specific ProGuard rules here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"app": {
"bundleName": "com.applib.jawahar_venugopal.hmosassignment",
"vendor": "applib",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 5,
"target": 5,
"releaseType": "Release"
}
},
"deviceConfig": {},
"module": {
"package": "com.applib.jawahar_venugopal.hmosassignment",
"name": ".MyApplication",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"name": "com.applib.jawahar_venugopal.hmosassignment.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:app_name",
"type": "page",
"launchType": "standard"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.applib.jawahar_venugopal.hmosassignment;

import com.applib.jawahar_venugopal.hmosassignment.slice.MainAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.window.service.WindowManager;

public class MainAbility extends Ability {
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setMainRoute(MainAbilitySlice.class.getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.applib.jawahar_venugopal.hmosassignment;

import ohos.aafwk.ability.AbilityPackage;

public class MyApplication extends AbilityPackage {
@Override
public void onInitialize() {
super.onInitialize();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.applib.jawahar_venugopal.hmosassignment.customview;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
import ohos.agp.utils.Rect;
import ohos.app.Context;

public class CustomButton extends Component implements Component.DrawTask {

private static final String BUTTON_COLOR_ATTR = "button_color";
private static final String BUTTON_TEXT_ATTR = "button_text";
private static final String BUTTON_TEXT_SIZE_ATTR = "button_text_size";
private static final String BUTTON_TEXT_COLOR_ATTR = "button_text_color";

private Color mButtonColor = Color.BLUE;
private String mButtonText = "Text";
private int mButtonTextSize = 50;
private Color mButtonTextColor = Color.BLACK;


private Paint mButtonPaint;
private Paint mButtonTextPaint;

public CustomButton(Context context) {
super(context);
init(null);
}

public CustomButton(Context context, AttrSet attrSet) {
super(context, attrSet);
init(attrSet);
}

public CustomButton(Context context, AttrSet attrSet, String styleName) {
super(context, attrSet, styleName);
init(attrSet);
}

private void init(AttrSet attrSet) {
if (attrSet != null) {
mButtonColor = attrSet.getAttr(BUTTON_COLOR_ATTR).isPresent() ? attrSet.getAttr(BUTTON_COLOR_ATTR).get().getColorValue() : mButtonColor;
mButtonText = attrSet.getAttr(BUTTON_TEXT_ATTR).isPresent() ? attrSet.getAttr(BUTTON_TEXT_ATTR).get().getStringValue() : mButtonText;
mButtonTextSize = attrSet.getAttr(BUTTON_TEXT_SIZE_ATTR).isPresent() ? attrSet.getAttr(BUTTON_TEXT_SIZE_ATTR).get().getIntegerValue() : mButtonTextSize;
mButtonTextColor = attrSet.getAttr(BUTTON_TEXT_COLOR_ATTR).isPresent() ? attrSet.getAttr(BUTTON_TEXT_COLOR_ATTR).get().getColorValue() : mButtonTextColor;
}
initPaint();
addDrawTask(this);
}

private void initPaint() {
mButtonPaint = new Paint();
mButtonPaint.setColor(mButtonColor);
mButtonPaint.setStyle(Paint.Style.FILL_STYLE);

mButtonTextPaint = new Paint();
mButtonTextPaint.setColor(mButtonTextColor);
mButtonTextPaint.setTextSize(mButtonTextSize);
}

@Override
public void onDraw(Component component, Canvas canvas) {
int width = getEstimatedWidth();
int height = getEstimatedHeight();

Rect buttonRect = new Rect(0, 0, width, height);
canvas.drawRect(buttonRect, mButtonPaint);

Rect textBounds = mButtonTextPaint.getTextBounds(mButtonText);
float xPos = buttonRect.getCenterX() - (textBounds.getWidth() / 2);
float yPos = buttonRect.getCenterY() + (textBounds.getHeight() / 2);
canvas.drawText(mButtonTextPaint, mButtonText, xPos, yPos);
}
}
Loading